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

fix(datepicker): pass through null #5275

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div><input ng-model="date" uib-datepicker-popup min-date="minDate" is-open="true"><div>')($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('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($rootScope);
Expand All @@ -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('<div><input ng-model="date" uib-datepicker-popup max-date="maxDate" is-open="true"><div>')($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('<div><input ng-model="date" uib-datepicker-popup show-button-bar="showBar" is-open="true"><div>')($rootScope);
Expand Down