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

Bugfix: Datepicker doesn't mark input field invalid if the date is invalid #1845

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
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