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

Commit

Permalink
fix(datepicker): fix popup updateOn: default support
Browse files Browse the repository at this point in the history
- Fix support for ng-model-options with `updateOn: blur`

Closes #5529
  • Loading branch information
B8li authored and wesleycho committed Feb 24, 2016
1 parent 74a1d04 commit 47e412e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,11 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
popupEl = angular.element('<div uib-datepicker-popup-wrap><div uib-datepicker></div></div>');
$scope.ngModelOptions = angular.copy(ngModelOptions);
$scope.ngModelOptions.timezone = null;
if ($scope.ngModelOptions.updateOnDefault === true) {
$scope.ngModelOptions.updateOn = $scope.ngModelOptions.updateOn ?
$scope.ngModelOptions.updateOn + ' default' : 'default';
}

popupEl.attr({
'ng-model': 'date',
'ng-model-options': 'ngModelOptions',
Expand Down
24 changes: 24 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3645,6 +3645,30 @@ describe('datepicker', function() {
});
});

describe('works with ngModelOptions updateOn : "default"', function() {
var $timeout, wrapElement;

beforeEach(inject(function(_$document_, _$sniffer_, _$timeout_) {
$document = _$document_;
$timeout = _$timeout_;
$rootScope.isopen = true;
$rootScope.date = new Date('2010-09-30T10:00:00.000Z');
wrapElement = $compile('<div><input ng-model="date" ' +
'ng-model-options="{ updateOn: \'default\' }" ' +
'uib-datepicker-popup is-open="isopen"><div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
}));

it('should close the popup and update the input when a day is clicked', function() {
clickOption(17);
assignElements(wrapElement);
expect(dropdownEl.length).toBe(0);
expect(inputEl.val()).toBe('2010-09-15');
expect($rootScope.date).toEqual(new Date('2010-09-15T10:00:00.000Z'));
});
});

describe('attribute `datepickerOptions`', function() {
describe('show-weeks', function() {
beforeEach(function() {
Expand Down

0 comments on commit 47e412e

Please sign in to comment.