From 039b991d3f23bc903d8ea5caccefce9b1621c254 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Fri, 15 Jan 2016 16:31:46 -0800 Subject: [PATCH] fix(datepicker): pass through null - When `minDate` or `maxDate` is `null` in the popup, pass through value to inline datepicker --- src/datepicker/datepicker.js | 14 +++++++++++--- src/datepicker/test/datepicker.spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 241abcf3c4..ed7e7537ad 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -685,10 +685,18 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi scope.$parent.$watch(getAttribute, function(value) { if (key === 'minDate' || key === 'maxDate') { - cache[key] = angular.isDate(value) ? dateParser.fromTimezone(new Date(value), ngModelOptions.timezone) : new Date(dateFilter(value, 'medium')); + if (value === null) { + cache[key] = null; + } else if (angular.isDate(value)) { + cache[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); + } else { + cache[key] = new Date(dateFilter(value, 'medium')); + } + + scope.watchData[key] = value === null ? null : cache[key]; + } else { + scope.watchData[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); } - - scope.watchData[key] = cache[key] || dateParser.fromTimezone(new Date(value), ngModelOptions.timezone); }); datepickerEl.attr(cameltoDash(key), 'watchData.' + key); diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 11eb8c521b..d863666007 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -2173,6 +2173,18 @@ describe('datepicker', function() { expect(buttons.eq(0).prop('disabled')).toBe(true); })); + it('should not disable any button if min date is null', function() { + $rootScope.minDate = null; + var wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + assignButtonBar(); + + for (var i = 0; i < buttons.length; i++) { + expect(buttons.eq(i).prop('disabled')).toBe(false); + } + }); + it('should disable today button if after max date', function() { $rootScope.maxDate = new Date().setDate(new Date().getDate() - 2); var wrapElement = $compile('
')($rootScope); @@ -2183,6 +2195,18 @@ describe('datepicker', function() { expect(buttons.eq(0).prop('disabled')).toBe(true); }); + it('should not disable any button if max date is null', function() { + $rootScope.maxDate = null; + var wrapElement = $compile('
')($rootScope); + $rootScope.$digest(); + assignElements(wrapElement); + assignButtonBar(); + + for (var i = 0; i < buttons.length; i++) { + expect(buttons.eq(i).prop('disabled')).toBe(false); + } + }); + it('should remove bar', function() { $rootScope.showBar = false; var wrapElement = $compile('
')($rootScope);