Is there a way to reset a reactive form group into its initial values instead of get it empty using .reset()
method ?
I have the following stackblitz, where the default selected value is Parent
, and if the user change it to sister, and wants to get the form to initial value, click on reset button to do so.
Currently, I tried:
this.formGroup.reset();
//Or
this.formGroup.markAsPristine;
//Or
this.formGroup.markAsTouched
The .reset()
reset the form completly.
P.S. Some people may say that the user can re-select the default value instead of clicking on reset button. But in my case, I have a huge user form where he needs to update his information, and he may needs to reset to initial values if he was mistaken in some values.
You can save the form initial values:
this.initialValues = this.formGroup.value;
And then pass those values to the reset function:
this.formGroup.reset(this.initialValues);