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

Commit

Permalink
fix(datepicker): mark input field as invalid if the date is invalid
Browse files Browse the repository at this point in the history
Closes #1845
  • Loading branch information
rickirunge authored and bekos committed Feb 27, 2014
1 parent 0d4c2e2 commit 467dd15
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
if (!viewValue) {
ngModel.$setValidity('date', true);
return null;
} else if (angular.isDate(viewValue)) {
} else if (angular.isDate(viewValue) && !isNaN(viewValue)) {
ngModel.$setValidity('date', true);
return viewValue;
} else if (angular.isString(viewValue)) {
Expand Down
9 changes: 9 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ describe('datepicker directive', function () {
testCalendar();
expect(angular.isDate($rootScope.date)).toBe(true);
});

it('to a date that is invalid, it gets invalid', function() {
$rootScope.date = new Date('pizza');
$rootScope.$digest();
expect(element.hasClass('ng-invalid')).toBeTruthy();
expect(element.hasClass('ng-invalid-date')).toBeTruthy();
expect(angular.isDate($rootScope.date)).toBe(true);
expect(isNaN($rootScope.date)).toBe(true);
});
});

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

0 comments on commit 467dd15

Please sign in to comment.