Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular2 formcontrol stays dirty even if set to original value

Tags:

forms

angular

When I change a value in an input field, the corresponding form-control is set to dirty. When I revert my change (by typing in the input field) the form-control stays dirty. Is this intended, is this a bug or do I do something wrong?

like image 288
Galdor Avatar asked Dec 07 '16 16:12

Galdor


1 Answers

Well, yes it's intended to work that way since:

A control is dirty if the user has changed the value in the UI. (docs entry)

..and not if the value is different from the starting value.


In case you want to revert the dirty state you could use the markAsPristine() (docs entry) on your AbstractControl. (eg trigger it by click on a button or when subscribing to the valueChanges observable of the AbstractControl and compare the new value to a previously stored one...)

like image 129
benny_boe Avatar answered Sep 29 '22 12:09

benny_boe