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

Commit

Permalink
fix(datepicker): pass through null
Browse files Browse the repository at this point in the history
- When `minDate` or `maxDate` is `null` in the popup, pass through value to inline datepicker
  • Loading branch information
wesleycho committed Jan 16, 2016
1 parent 2cb3bc2 commit 039b991
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
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

0 comments on commit 039b991

Please sign in to comment.