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

Commit 467dd15

Browse files
rickirungebekos
authored andcommittedFeb 27, 2014
fix(datepicker): mark input field as invalid if the date is invalid
Closes #1845
1 parent 0d4c2e2 commit 467dd15

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

‎src/datepicker/datepicker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
368368
if (!viewValue) {
369369
ngModel.$setValidity('date', true);
370370
return null;
371-
} else if (angular.isDate(viewValue)) {
371+
} else if (angular.isDate(viewValue) && !isNaN(viewValue)) {
372372
ngModel.$setValidity('date', true);
373373
return viewValue;
374374
} else if (angular.isString(viewValue)) {

‎src/datepicker/test/datepicker.spec.js

+9
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,15 @@ describe('datepicker directive', function () {
248248
testCalendar();
249249
expect(angular.isDate($rootScope.date)).toBe(true);
250250
});
251+
252+
it('to a date that is invalid, it gets invalid', function() {
253+
$rootScope.date = new Date('pizza');
254+
$rootScope.$digest();
255+
expect(element.hasClass('ng-invalid')).toBeTruthy();
256+
expect(element.hasClass('ng-invalid-date')).toBeTruthy();
257+
expect(angular.isDate($rootScope.date)).toBe(true);
258+
expect(isNaN($rootScope.date)).toBe(true);
259+
});
251260
});
252261

253262
describe('not to a Date object', function() {

0 commit comments

Comments
 (0)