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

fix(datepicker): min-date/max-date: parse fix for literals #4841

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
6 changes: 3 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
angular.forEach(['minDate', 'maxDate'], function(key) {
if ($attrs[key]) {
$scope.$parent.$watch($attrs[key], function(value) {
self[key] = value ? new Date(value) : null;
self[key] = value ? angular.isDate(value) ? new Date(value) : new Date(dateFilter(value, 'medium')) : null;
self.refreshView();
});
} else {
Expand Down Expand Up @@ -628,10 +628,10 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
if (attrs[key]) {
var getAttribute = $parse(attrs[key]);
scope.$parent.$watch(getAttribute, function(value) {
scope.watchData[key] = value;
if (key === 'minDate' || key === 'maxDate') {
cache[key] = new Date(value);
cache[key] = angular.isDate(value) ? new Date(value) : new Date(dateFilter(value, 'medium'));
}
scope.watchData[key] = cache[key] || value;
});
datepickerEl.attr(cameltoDash(key), 'watchData.' + key);

Expand Down
25 changes: 25 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,20 @@ describe('datepicker', function() {

});

describe('`min-date` attribute', function () {
beforeEach(function() {
element = $compile('<uib-datepicker ng-model="date" min-date="\'2010-09-05\'"></uib-datepicker>')($rootScope);
$rootScope.$digest();
});

it('accepts literals, \'yyyy-MM-dd\' case', function() {
var buttons = getAllOptionsEl();
angular.forEach(buttons, function(button, index) {
expect(angular.element(button).prop('disabled')).toBe(index < 7);
});
});
});

describe('`max-date` attribute', function() {
beforeEach(function() {
$rootScope.maxdate = new Date('September 25, 2010');
Expand Down Expand Up @@ -1982,6 +1996,17 @@ describe('datepicker', function() {
expect(buttons.eq(0).prop('disabled')).toBe(true);
});

it('should disable today button if before min date, yyyy-MM-dd case', inject(function(dateFilter) {
var minDate = new Date(new Date().setDate(new Date().getDate() + 1));
var literalMinDate = dateFilter(minDate, 'yyyy-MM-dd');
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup="yyyy-MM-dd" min-date="\'' + literalMinDate + '\'" is-open="true"><div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
assignButtonBar();

expect(buttons.eq(0).prop('disabled')).toBe(true);
}));

it('should disable today button if after max date', function() {
$rootScope.maxDate = new Date().setDate(new Date().getDate() - 2);
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($rootScope);
Expand Down