diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 799c652941..40f8d052fb 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -513,7 +513,8 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar appendToBody = angular.isDefined(attrs.datepickerAppendToBody) ? scope.$parent.$eval(attrs.datepickerAppendToBody) : datepickerPopupConfig.appendToBody, onOpenFocus = angular.isDefined(attrs.onOpenFocus) ? scope.$parent.$eval(attrs.onOpenFocus) : datepickerPopupConfig.onOpenFocus, datepickerPopupTemplateUrl = angular.isDefined(attrs.datepickerPopupTemplateUrl) ? attrs.datepickerPopupTemplateUrl : datepickerPopupConfig.datepickerPopupTemplateUrl, - datepickerTemplateUrl = angular.isDefined(attrs.datepickerTemplateUrl) ? attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl; + datepickerTemplateUrl = angular.isDefined(attrs.datepickerTemplateUrl) ? attrs.datepickerTemplateUrl : datepickerPopupConfig.datepickerTemplateUrl, + cache = {}; scope.showButtonBar = angular.isDefined(attrs.showButtonBar) ? scope.$parent.$eval(attrs.showButtonBar) : datepickerPopupConfig.showButtonBar; @@ -521,6 +522,19 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar return scope[key + 'Text'] || datepickerPopupConfig[key + 'Text']; }; + scope.isDisabled = function(date) { + if (date === 'today') { + date = new Date(); + } + + return ((scope.watchData.minDate && scope.compare(date, cache.minDate) < 0) || + (scope.watchData.maxDate && scope.compare(date, cache.maxDate) > 0)); + }; + + scope.compare = function(date1, date2) { + return (new Date(date1.getFullYear(), date1.getMonth(), date1.getDate()) - new Date(date2.getFullYear(), date2.getMonth(), date2.getDate())); + }; + var isHtml5DateInput = false; if (datepickerPopupConfig.html5Types[attrs.type]) { dateFormat = datepickerPopupConfig.html5Types[attrs.type]; @@ -591,6 +605,9 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar 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); + } }); datepickerEl.attr(cameltoDash(key), 'watchData.' + key); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index ac33776936..8ea3a774aa 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1906,6 +1906,26 @@ describe('datepicker directive', function() { expect(buttons.eq(2).text()).toBe('CloseME'); }); + it('should disable today button if before min date', function() { + $rootScope.minDate = new Date().setDate(new Date().getDate() + 1); + var wrapElement = $compile('