From 96f36d0bee4276477ebf5c534b558988509e06f1 Mon Sep 17 00:00:00 2001 From: Dave Anderson Date: Fri, 27 Nov 2015 08:12:06 -0500 Subject: [PATCH] fix(datepicker): min-date/max-date: parse fix for literals BREAKING CHANGE: only display formats or altInputFormats are valid for literal dates Closes #3437 --- src/datepicker/datepicker.js | 4 ++-- src/datepicker/test/datepicker.spec.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index a66465147d..98fe8be72c 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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] = new Date(parseDate(value)); } + scope.watchData[key] = cache[key] || value; }); datepickerEl.attr(cameltoDash(key), 'watchData.' + key); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 972bb57a8c..b5a9856f01 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1982,6 +1982,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('
')($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('
')($rootScope);