Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit 47e412e

Browse files
B8liwesleycho
authored andcommitted
fix(datepicker): fix popup updateOn: default support
- Fix support for ng-model-options with `updateOn: blur` Closes #5529
1 parent 74a1d04 commit 47e412e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/datepicker/datepicker.js

+5
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
836836
popupEl = angular.element('<div uib-datepicker-popup-wrap><div uib-datepicker></div></div>');
837837
$scope.ngModelOptions = angular.copy(ngModelOptions);
838838
$scope.ngModelOptions.timezone = null;
839+
if ($scope.ngModelOptions.updateOnDefault === true) {
840+
$scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ?
841+
$scope.ngModelOptions.updateOn + ' default' : 'default';
842+
}
843+
839844
popupEl.attr({
840845
'ng-model': 'date',
841846
'ng-model-options': 'ngModelOptions',

src/datepicker/test/datepicker.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -3645,6 +3645,30 @@ describe('datepicker', function() {
36453645
});
36463646
});
36473647

3648+
describe('works with ngModelOptions updateOn : "default"', function() {
3649+
var $timeout, wrapElement;
3650+
3651+
beforeEach(inject(function(_$document_, _$sniffer_, _$timeout_) {
3652+
$document = _$document_;
3653+
$timeout = _$timeout_;
3654+
$rootScope.isopen = true;
3655+
$rootScope.date = new Date('2010-09-30T10:00:00.000Z');
3656+
wrapElement = $compile('<div><input ng-model="date" ' +
3657+
'ng-model-options="{ updateOn: \'default\' }" ' +
3658+
'uib-datepicker-popup is-open="isopen"><div>')($rootScope);
3659+
$rootScope.$digest();
3660+
assignElements(wrapElement);
3661+
}));
3662+
3663+
it('should close the popup and update the input when a day is clicked', function() {
3664+
clickOption(17);
3665+
assignElements(wrapElement);
3666+
expect(dropdownEl.length).toBe(0);
3667+
expect(inputEl.val()).toBe('2010-09-15');
3668+
expect($rootScope.date).toEqual(new Date('2010-09-15T10:00:00.000Z'));
3669+
});
3670+
});
3671+
36483672
describe('attribute `datepickerOptions`', function() {
36493673
describe('show-weeks', function() {
36503674
beforeEach(function() {

0 commit comments

Comments
 (0)