Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-dirty not reset after user manually resets field?

Tags:

angular

What's the reasoning behind Angular's decision to not reset an input's class from ng-dirty to ng-pristine after the user manually set a field back to its initial value?

I want to execute my save logic only if the user actually changed some of the form's data. Is there a better way than to manually hold the initial state and check for differences on submit?

like image 616
D.R. Avatar asked Dec 03 '25 02:12

D.R.


1 Answers

The status is dirty this means the user changed the value. Angular doesn't track the original value though and therefore can't tell if the original value was restored.

If you want to know if the value changed, you have to store the value and on submit compare yourself if it has changed.

like image 68
Günter Zöchbauer Avatar answered Dec 04 '25 20:12

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!