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

fix(datepicker): correct datepicker-mode binding for popup #2184

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
22 changes: 17 additions & 5 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
self[key] = angular.isDefined($attrs[key]) ? (index < 8 ? $interpolate($attrs[key])($scope.$parent) : $scope.$parent.$eval($attrs[key])) : datepickerConfig[key];
});

// Watchable attributes
// Watchable date attributes
angular.forEach(['minDate', 'maxDate'], function( key ) {
if ( $attrs[key] ) {
$scope.$parent.$watch($parse($attrs[key]), function(value) {
Expand Down Expand Up @@ -477,12 +477,24 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
});
}

angular.forEach(['minDate', 'maxDate'], function( key ) {
scope.watchData = {};
angular.forEach(['minDate', 'maxDate', 'datepickerMode'], function( key ) {
if ( attrs[key] ) {
scope.$parent.$watch($parse(attrs[key]), function(value){
scope[key] = value;
var getAttribute = $parse(attrs[key]);
scope.$parent.$watch(getAttribute, function(value){
scope.watchData[key] = value;
});
datepickerEl.attr(cameltoDash(key), key);
datepickerEl.attr(cameltoDash(key), 'watchData.' + key);

// Propagate changes from datepicker to outside
if ( key === 'datepickerMode' ) {
var setAttribute = getAttribute.assign;
scope.$watch('watchData.' + key, function(value, oldvalue) {
if ( value !== oldvalue ) {
setAttribute(scope.$parent, value);
}
});
}
}
});
if (attrs.dateDisabled) {
Expand Down
1 change: 0 additions & 1 deletion src/datepicker/docs/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($
startingDay: 1
};

$scope.initDate = new Date('2016-15-20');
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
});
19 changes: 19 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,25 @@ describe('datepicker directive', function () {
}
});
});

describe('`datepicker-mode`', function () {
beforeEach(inject(function() {
$rootScope.date = new Date('August 11, 2013');
$rootScope.mode = 'month';
wrapElement = $compile('<div><input ng-model="date" datepicker-popup datepicker-mode="mode"></div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
}));

it('shows the correct title', function() {
expect(getTitle()).toBe('2013');
});

it('updates binding', function() {
clickTitleButton();
expect($rootScope.mode).toBe('year');
});
});
});

describe('with empty initial state', function () {
Expand Down