diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index a66465147d..c1ff1a6e94 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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 { @@ -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); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 972bb57a8c..e112144823 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -965,6 +965,20 @@ describe('datepicker', function() { }); + describe('`min-date` attribute', function () { + beforeEach(function() { + element = $compile('')($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'); @@ -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('
')($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);