-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Input type="number" invalid on load if ng-required is used #9106
Comments
beta.19 vs rc.2 demos: 1.3.0-beta.19: http://codepen.io/ItsLeeOwen/pen/Fjxnh |
Actually, as far as I can tell, it is not that anything is actually found to be invalid. I believe the problem is that The problem arises when the Since Thus, moving the parser added by What do you think, you inputDirectives-savvy people ? |
This is a POC fiddle showing the problem going away (without breaking proper validation). |
…er] with observed attributes When no value has been set for an input[number] it's viewValue is undefined. This lead to false parse 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 undefined when the input is invalid and returns the value unchanged when the input is valid. Thus, when the value itself is undefined, the NgModelController is tricked into believing there is a native validation error. Closes angular#9106
…er] 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
@tbosch I'm assigning this to you. If you can't get around to it this week then I can have a look at the start of next week. |
So this was broken by db044c4 as far as I can tell. It doesn't really make any sense for us to be parsing model values, that's like the opposite of what model values are for. I don't think I can bug matsko about this right now, unfortunately :( @tbosch am I crazy? Is there a good reason why we are parsing values which should have already been parsed if they needed to be parsed? edit I guess it really is parsing view values, just... the view value might not actually exist yet. :c |
@caitp, yes, we are reparsing the view value here so that we can react to changes in |
A regression has occurred in Angular version 1.3.0-rc.1 where using
ng-required
on an input withtype="number"
results in incorrect behaviour on initialisation.The issue is that regardless of what the
ng-required
expression returns, the input is marked as having an invalid number when it is empty due to being bound to a non-existent property.I have reproduced this with a Plunkr, which shows output like so:
I was able to have a hacky workaround locally by creating a directive that would
shift()
thebadInputChecker
parser function from the start of thengModelController.$parsers
array, and push it onto the end instead. Thus it is likely related to the fact that thebadInputChecker
is added as the first parser function.The text was updated successfully, but these errors were encountered: