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

Commit

Permalink
fix(datepicker): correct datepicker-mode binding for popup
Browse files Browse the repository at this point in the history
Fixes #2180
Closes #2184
  • Loading branch information
bekos authored and pkozlowski-opensource committed Jun 11, 2014
1 parent 5cd6f4a commit 63ae06c
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

1 comment on commit 63ae06c

@Maus3rVonDutch
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Thnx for fixing the binding for the datepicker mode in the popup. But there are still more attributes that need fixing for the popup. MinMode and MaxMode should also be fixed, because currently you cannot create a monthpicker control (were you would only need to select a month, not a date). With the current fix you can set the initial datepicker mode for the popup, but because the MinMode and MaxMode are not watched, you are still drilling down to a date when you actually want to select the month.

Please sign in to comment.