Angular 2 reset form to initial data without having to set each formcontrol individually -
i have formgroup open in edit mode , initialize proper data. save initial data in editform.
after doing changes want reset changes initial values, like:
this.formgroup.reset(this.stafftoedit);
but put blank in every field. workaround found
this.formgroup.reset({field1 : this.editform.field1}); ...
the thing need more generic resets fields initial value without having go through each formcontrol.
is possible do?
what keep reference of initial values , use patchvalue()
call markaspristine()
set form values were, , marking entire form pristine.
const initialformvalues { firstname: 'joe', surname: 'doe' }; ... reset() { this.formgroup.patchvalue(initialformvalues); this.formgroup.markaspristine(); }
or i'm guessing in case:
reset() { this.formgroup.patchvalue(this.editform.value); this.formgroup.markaspristine(); }
Comments
Post a Comment