ngForm stays $dirty after control.$setPristine() #13715
Comments
I'm pretty sure this is how it is supposed to work. It's not an unreasonable feature to request, but it would add a tiny bit of overhead (which won't be necessary for most apps). If you need such functionality, you can always implement a work-around. @Narretz, do you think it is reasonable to check if all controls are |
User expectation is probably that the form is set to $pristine, and I can see how that makes sense. We have the same problem with $setValidity, too, afaik. |
When calling $setPristine on the nested form or control, form becomes $pristine of all the nested controls are pristine Closes angular#13715
I wrote some brute force solution, but.. what if we will keep track of number of nested pristine controls/forms? 0 by default, it will be increased in |
Having an internal counter also seems like a viable solution. I can't think of a corner case that could not be handled with such an implementation (if implemented properly). |
Hi, thanks for considering this. I understand that revalidating the entire form to check for $pristine is a an inexpensive operation relative to setting the form to $dirty when a single control is set dirty. I like the idea of counters for the $touched, $untouched, $pristine and $dirty status of each field, since we only care whether or not the counter is 0 each. |
…Pristine() (brute force version) When calling $setPristine on the nested form or control, form becomes $pristine of all the nested controls are pristine Closes angular#13715
…(brute force version) When calling $setPristine on the nested form or control, form becomes $pristine of all the nested controls are pristine Closes angular#13715
I take it this issue has never been resolved, and probably won't be? |
@adamreisnz That's correct. It should be possible to implement this logic by using https://docs.angularjs.org/api/ng/type/form.FormController#$getControls and a custom $setPristine implementation. |
Hi there. Frustrating problem. in an ngForm, if in my controller I set one of the form's controls to $dirty (via control.$setDirty()), then in the controller set the same control to $pristine, the form remains $dirty.
I'm pretty sure this shouldn't happen, and is getting kludgy to fix. I'm using Angular 1.4.8.
Plunkr:
https://plnkr.co/edit/6noEtj6vbMkqxiKK6Yp7?p=preview
Thanks
The text was updated successfully, but these errors were encountered: