Skip to content

Commit

Permalink
fix(datepicker): correct datepicker-mode binding for popup
Browse files Browse the repository at this point in the history
  • Loading branch information
bekos authored and dearlordylord committed Jun 18, 2014
1 parent 6d3494f commit 976854d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
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

0 comments on commit 976854d

Please sign in to comment.