-
Notifications
You must be signed in to change notification settings - Fork 27.5k
$setValidity somehow breaks model binding in 1.3.0 Beta 12 and after #8080
Comments
Hi, so what's actually happening is that the It's not being removed from the form, it's just that http://jsfiddle.net/QruVT/ here's an example --- if you type a name which contains a hyphen, you should see the property disappear (it becomes invalid), but if it's valid (no hyphen), the property is visible. As you can see from http://jsfiddle.net/GZ5Nt/, this works the same in beta.11. Basically, the issue here is that validation is very much tied to the reporting of the value. I've proposed a change which would separate these things and make them less of a maze, so that it's easier to understand. But currently yeah, since values and validity are very tied, you need to do some work to make this use case work. If you're manually setting the view value to defer validation, you might want to look into using |
Thanks, i think i got it. So basically an invalid field will also make its model value I used this until now to invalidate fields after getting errors from server (i'm not validating with AngularJS). I get a JSON array with field names and errors, and then populate them to the fields with But this makes it impossible to re-submit the model again to the server, because now the server always complains about empty So the only way i see for now is to remove somehow the false validity on an input, once the user changed the value of it. I tried it here http://jsfiddle.net/mpiecko/q2s7Z/3/ with another button, but the Michael |
So just as a quick update and notice: since 1.3.0 Beta 12 an input field with a manually set Here a JSFiddle to try it: http://jsfiddle.net/mpiecko/q2s7Z/4/ Michael |
I guess this is related to the discussion at #7976 |
That the model is no longer updated when at least one $validity prop is invalid is actually consistent. It shouldn't matter if it is done by a $validator or by directly calling $setValidity. What we really need is a way to set modelValues to model even if they are invalid, aka decouple checking validity and setting model value And we should check more thoroughly for breaking changes |
I see the point why an invalid input shouldn't update the model. But up until Beta 11 (and all versions before) this was an easy and understandable way to bypass Angular validation and do it server side (also mentioned in many posts on the net):
Since Beta 12 this no longer works, because in step 3 the model property gets But maybe server side validation should be handled differently in Angular 1.3? |
Yeah, I think I used that way in some project, too. I'm not saying it should stay the way it is, but that it worked before is also not a sign that this was good design. But it's very broken. You cannot even get the $modelValue from the submit handler because it's never set. :/ |
Has this been fixed? |
doesn't seem like it. Are there any plans for this to make it into one of the 1.3.0 rc's? |
I think this is the logic that's setting angular.js/src/ng/directive/input.js Line 1771 in c3064f7
angular.js/src/ng/directive/input.js Line 1966 in c3064f7
|
@jeffbcross This is actually the same issue as described in #8357 (comment) |
Ok, the Closing this then. Please comment if you have a usecase that could not be solved via the new |
Reopening this, as we probably don't want to force users to use the |
Calling `ctrl.$setValidity()` with a an error key that does not belong to a validator in `ctrl.$validator` should not result in setting the model to `undefined` on the next input change. This bug was introduced in 1.3.0-beta.12. Closes angular#8357 Fixes angular#8080
Here is an updated jsfiddle: http://jsfiddle.net/q2s7Z/7/ |
Since version 1.3.0 Beta 12 my models are losing properties after manually invalidating input fields. I created a JSFiddle to demonstrate this behavior.
Type something in the field, press the button to invalidate the field, and type something in the field again. In Beta 11 my model stays up to date with the input field (see "Debug Model" below):
http://jsfiddle.net/mpiecko/q2s7Z/
Now watch the "Debug Model" if you repeat these steps with Beta 12. The "fullName" property disappears when you type something in the field, invalidate it with the button, and then type something again:
http://jsfiddle.net/mpiecko/q2s7Z/1/
I'm not sure if this is a bug or an upcoming change in handling of form errors.
Michael
The text was updated successfully, but these errors were encountered: