diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 0403d6cf35b2..4b0d8cf4b1c3 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1326,7 +1326,7 @@ function createDateInputType(type, regexp, parseDate, format) { } function parseObservedDateValue(val) { - return isDefined(val) ? (isDate(val) ? val : parseDate(val)) : undefined; + return isDefined(val) && !isDate(val) ? parseDate(val) || undefined : val; } }; } diff --git a/test/ng/directive/inputSpec.js b/test/ng/directive/inputSpec.js index 3c92625a1b43..95763b1d2bdb 100644 --- a/test/ng/directive/inputSpec.js +++ b/test/ng/directive/inputSpec.js @@ -688,6 +688,14 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.min).toBeTruthy(); }); + + it('should validate if min is empty', function() { + $rootScope.minVal = undefined; + $rootScope.value = new Date(-9999, 0, 1, 0, 0, 0); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.min).toBeFalsy(); + }); }); describe('max', function() { @@ -722,6 +730,14 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.max).toBeTruthy(); }); + + it('should validate if max is empty', function() { + $rootScope.maxVal = undefined; + $rootScope.value = new Date(9999, 11, 31, 23, 59, 59); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.max).toBeFalsy(); + }); }); }); @@ -886,6 +902,14 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.min).toBeTruthy(); }); + + it('should validate if min is empty', function() { + $rootScope.minVal = undefined; + $rootScope.value = new Date(-9999, 0, 1, 0, 0, 0); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.min).toBeFalsy(); + }); }); describe('max', function() { @@ -921,6 +945,14 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.max).toBeTruthy(); }); + + it('should validate if max is empty', function() { + $rootScope.maxVal = undefined; + $rootScope.value = new Date(9999, 11, 31, 23, 59, 59); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.max).toBeFalsy(); + }); }); }); @@ -1119,6 +1151,14 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.min).toBeTruthy(); }); + + it('should validate if min is empty', function() { + $rootScope.minVal = undefined; + $rootScope.value = new Date(-9999, 0, 1, 0, 0, 0); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.min).toBeFalsy(); + }); }); describe('max', function() { @@ -1153,6 +1193,14 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.max).toBeTruthy(); }); + + it('should validate if max is empty', function() { + $rootScope.maxVal = undefined; + $rootScope.value = new Date(9999, 11, 31, 23, 59, 59); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.max).toBeFalsy(); + }); }); @@ -1428,12 +1476,21 @@ describe('input', function() { expect(inputElm).toBeInvalid(); expect($rootScope.form.alias.$error.min).toBeTruthy(); }); + + it('should validate if min is empty', function() { + $rootScope.minVal = undefined; + $rootScope.value = new Date(-9999, 0, 1, 0, 0, 0); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.min).toBeFalsy(); + }); }); describe('max', function() { var inputElm; beforeEach(function() { - inputElm = helper.compileInput(''); + $rootScope.maxVal = '22:30:00'; + inputElm = helper.compileInput(''); }); it('should invalidate', function() { @@ -1449,11 +1506,19 @@ describe('input', function() { expect(+$rootScope.value).toBe(+new Date(1970, 0, 1, 5, 30, 0)); expect($rootScope.form.alias.$error.max).toBeFalsy(); }); + + it('should validate if max is empty', function() { + $rootScope.maxVal = undefined; + $rootScope.value = new Date(9999, 11, 31, 23, 59, 59); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.max).toBeFalsy(); + }); }); it('should validate even if max value changes on-the-fly', function() { - $rootScope.max = '4:02:00'; + $rootScope.max = '04:02:00'; var inputElm = helper.compileInput(''); helper.changeInputValueTo('05:34:00'); @@ -1481,7 +1546,7 @@ describe('input', function() { it('should validate even if ng-max value changes on-the-fly', function() { - $rootScope.max = '4:02:00'; + $rootScope.max = '04:02:00'; var inputElm = helper.compileInput(''); helper.changeInputValueTo('05:34:00'); @@ -1706,6 +1771,16 @@ describe('input', function() { expect($rootScope.form.myControl.$error.min).toBeTruthy(); }); + + it('should validate if min is empty', function() { + var inputElm = helper.compileInput( + ''); + + $rootScope.value = new Date(-9999, 0, 1, 0, 0, 0); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.min).toBeFalsy(); + }); }); describe('max', function() { @@ -1735,6 +1810,16 @@ describe('input', function() { expect($rootScope.form.myControl.$error.max).toBeTruthy(); }); + + it('should validate if max is empty', function() { + var inputElm = helper.compileInput( + ''); + + $rootScope.value = new Date(9999, 11, 31, 23, 59, 59); + $rootScope.$digest(); + + expect($rootScope.form.alias.$error.max).toBeFalsy(); + }); });