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

fix(datepicker): fix popup to work with ng-model-options:updateOn='default' #5529

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ 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