Skip to content

Commit 02a8436

Browse files
committed
fix(input): fix false initial 'number' validation error in input[number] with observed attributes
When no value has been set for an input[number] it's viewValue is undefined. This lead to false 'number' validation errors, when `ctrl.$validate()` was fired before interacting with the element. A typical situation of this happening is when other directives on the same element `$observe()` attribute values. (Such directives are ngRequired, min, max etc.) More specifically, the parser for native HTML5 validation returns either undefined (when the input is invalid) or the parsed value (when the input is valid). Thus, when the value itself is undefined, the NgModelController is tricked into believing that there is a native validation error. Closes angular#9106
1 parent 69730db commit 02a8436

File tree

1 file changed

+0
-18
lines changed

1 file changed

+0
-18
lines changed

test/ng/directive/inputSpec.js

-18
Original file line numberDiff line numberDiff line change
@@ -3689,15 +3689,6 @@ describe('input', function() {
36893689
expect(scope.form.alias.$error.required).toBeTruthy();
36903690
});
36913691

3692-
it('should be invalid when the user enters an invalid value', function() {
3693-
compileInput('<input type="number" ng-model="value" name="alias" ng-required="true" />');
3694-
3695-
changeInputValueTo('Hello, world !');
3696-
expect(inputElm.val()).toBe('');
3697-
expect(inputElm).toBeInvalid();
3698-
expect(scope.form.alias.$error.required).toBeTruthy();
3699-
});
3700-
37013692
it('should change from invalid to valid when the value is empty and the ngRequired expression changes to false', function() {
37023693
compileInput('<input type="number" ng-model="value" name="alias" ng-required="ngRequiredExpr" />');
37033694

@@ -3735,15 +3726,6 @@ describe('input', function() {
37353726
expect(scope.form.alias.$error.required).toBeFalsy();
37363727
});
37373728

3738-
it('should not have the "required" error flag set even if the value is not a number', function() {
3739-
compileInput('<input type="number" ng-model="value" name="alias" ng-required="false" />');
3740-
3741-
changeInputValueTo('Hello, world !');
3742-
expect(inputElm.val()).toBe('');
3743-
expect(inputElm).toBeValid();
3744-
expect(scope.form.alias.$error.required).toBeFalsy();
3745-
});
3746-
37473729
it('should not register required on non boolean elements', function() {
37483730
compileInput('<div ng-model="value" name="alias" ng-required="false">');
37493731

0 commit comments

Comments
 (0)