-
Notifications
You must be signed in to change notification settings - Fork 27.4k
docs(ngModel): $setViewValue does not check validity before updating model #3498
Conversation
…model. Removes an incorrect assertion in the docs for $setViewValue. It actually updates the model regardless of the control validity.
Thanks for the PR!
If you need to make changes to your pull request, you can update the commit with Thanks again for your help! |
thanks but this change wasn't quite correct either. I clarified the docs in a separate commit. thanks again. |
@IgorMinar Good call on the longer comment. However I think the sentence "if validators determine the value is invalid, the So, if you implement a custom validator, then just setting the control validity is not enough, you must also return |
@niallsmart - I agree that the model will be set to whatever the value is returned by the last $parser in the pipeline. As it turns out, all the built-in validation directives "do" set this return to |
@petebacondarwin the pull request linked to above clarifies this I think, which Igor merged earlier today. |
Hey guys! I'm a little bit confused, what is an idea behind setting $modelValue to the undefined if validation fails? In case we have a watcher for this value in a controller and ngModel becomes invalid and then back valid with the same value the watcher will be triggered again and again. Here's an example to illustrate my question. Please advise how to handle such cases? |
@rinatio - The idea is that the model should only contain valid values or
Then if you watch this |
@petebacondarwin thanks, it makes sense. Maybe it is possible to ask explicitly |
I would be interested to see your use-case, as in general people have not had this issue before. |
@petebacondarwin it is pretty simple. Every time input's value got changed, we send a new ajax request. In case |
Removes an incorrect assertion in the docs for $setViewValue. It actually updates the model regardless of the control validity.