From 4eeaa66afe8a4c2d5a179ce8fc2d699ffc2bf2de Mon Sep 17 00:00:00 2001 From: Ricki Runge Date: Sun, 23 Feb 2014 17:58:44 +0100 Subject: [PATCH] Datapicker now markes input field invalid if the date is invalid --- src/datepicker/datepicker.js | 2 +- src/datepicker/test/datepicker.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index 599f3c3562..b0a3b932a1 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -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)) { diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 9ecec1c69c..575dae700c 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -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() {