Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting values on a disabled form control triggers valueChanges of the form #229

Open
erikmom opened this issue Oct 20, 2021 · 0 comments
Open

Comments

@erikmom
Copy link
Contributor

erikmom commented Oct 20, 2021

Use case:
In our situation we have a subform where we can select a template. If a template is chosen, other subforms are updated with values from the template and the controls are disabled.

We are using valueChanges on the root form to conditionally setting the template values on the disabled controls (amongst quite some other things). When changing the template value, we are setting values on already disabled controls, which is done in ngx-sub-form.component.ts in the writeValue function there is some workaround implemented because of some reported bugs in angular forms regarding setting values on a disabled form.

const fgDisabled: boolean = this.formGroup.disabled;

this.formGroup.setValue(transformedValue, {
  emitEvent: false,
});

if (fgDisabled) {
  this.formGroup.disable();
}

Although the workaround 'fixes' this issue, it also triggers a valueChanges on the form again because of setting the formGroup to disabled again. I would expect that {emitEvent: false} should be used when disabling the formGroup again (just like is done when setting the value).

const fgDisabled: boolean = this.formGroup.disabled;

this.formGroup.setValue(transformedValue, {
  emitEvent: false,
});

if (fgDisabled) {
  this.formGroup.disable({ emitEvent: false });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant