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

Commit 78ba137

Browse files
committed
fix(datepicker): pass through null
- When `minDate` or `maxDate` is `null` in the popup, pass through value to inline datepicker Closes #5275 Fixes #5238
1 parent 2cb3bc2 commit 78ba137

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/datepicker/datepicker.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,18 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi
685685

686686
scope.$parent.$watch(getAttribute, function(value) {
687687
if (key === 'minDate' || key === 'maxDate') {
688-
cache[key] = angular.isDate(value) ? dateParser.fromTimezone(new Date(value), ngModelOptions.timezone) : new Date(dateFilter(value, 'medium'));
688+
if (value === null) {
689+
cache[key] = null;
690+
} else if (angular.isDate(value)) {
691+
cache[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
692+
} else {
693+
cache[key] = new Date(dateFilter(value, 'medium'));
694+
}
695+
696+
scope.watchData[key] = value === null ? null : cache[key];
697+
} else {
698+
scope.watchData[key] = dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
689699
}
690-
691-
scope.watchData[key] = cache[key] || dateParser.fromTimezone(new Date(value), ngModelOptions.timezone);
692700
});
693701

694702
datepickerEl.attr(cameltoDash(key), 'watchData.' + key);

src/datepicker/test/datepicker.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,18 @@ describe('datepicker', function() {
21732173
expect(buttons.eq(0).prop('disabled')).toBe(true);
21742174
}));
21752175

2176+
it('should not disable any button if min date is null', function() {
2177+
$rootScope.minDate = null;
2178+
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup min-date="minDate" is-open="true"><div>')($rootScope);
2179+
$rootScope.$digest();
2180+
assignElements(wrapElement);
2181+
assignButtonBar();
2182+
2183+
for (var i = 0; i < buttons.length; i++) {
2184+
expect(buttons.eq(i).prop('disabled')).toBe(false);
2185+
}
2186+
});
2187+
21762188
it('should disable today button if after max date', function() {
21772189
$rootScope.maxDate = new Date().setDate(new Date().getDate() - 2);
21782190
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($rootScope);
@@ -2183,6 +2195,18 @@ describe('datepicker', function() {
21832195
expect(buttons.eq(0).prop('disabled')).toBe(true);
21842196
});
21852197

2198+
it('should not disable any button if max date is null', function() {
2199+
$rootScope.maxDate = null;
2200+
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($rootScope);
2201+
$rootScope.$digest();
2202+
assignElements(wrapElement);
2203+
assignButtonBar();
2204+
2205+
for (var i = 0; i < buttons.length; i++) {
2206+
expect(buttons.eq(i).prop('disabled')).toBe(false);
2207+
}
2208+
});
2209+
21862210
it('should remove bar', function() {
21872211
$rootScope.showBar = false;
21882212
var wrapElement = $compile('<div><input ng-model="date" uib-datepicker-popup show-button-bar="showBar" is-open="true"><div>')($rootScope);

0 commit comments

Comments
 (0)