PatchValue in an angular subform made with ControlAccessValue cause parent form status to be Dirty

Viewed 447

I am building an app that uses nested form.

A nested form is a component that extends ControlAccessValue and speaks with the parent form through onTouched and onChanged function.

My problem is that when I patch a value in the SubForm the MainForm is marked as dirty. I would expect instead that both forms were dirty:false and pristine:true, that is actually what I would like to achieve.

I built a simple stackblitz to show you what I mean.

The question is: am I doing something wrong? Any help?

The example : https://stackblitz.com/edit/angular-ivy-b9twi8?

If you comment the line below you'll see that the parent form dirty value is set to false.

this.addressForm.get('street').setValue(this.streetValue);

Thank you all

1 Answers

I would suggest write this.addressForm.get('street').setValue(this.streetValue, {onlySelf: true}); to prevent making dirty main form

Related