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

Initially disabled form triggers valueChanges #170

Closed
4typen opened this issue May 5, 2020 · 1 comment · May be fixed by #218
Closed

Initially disabled form triggers valueChanges #170

4typen opened this issue May 5, 2020 · 1 comment · May be fixed by #218

Comments

@4typen
Copy link

4typen commented May 5, 2020

Hi,

I think i discovered a bug caused from the workaround #84

I have a form with few form fields. Some form fields have a subscription on their valueChanges-Event. If this value changes, we reset other fields.

Now the problem is, when the form is disabled by the disabled-attribute (or by this.formGroup.disable({ emitEvent: false });) as default, the valueChanges-Event from above triggers directly on opening the component.

Example:

public ngOnInit(): void {
    super.ngOnInit();

    this.formGroupControls.someField.valueChanges.subscribe(() => this.resetOtherField());

    if (this.formModel.isReadonly) {
      this.formGroup.disable(); // Passing { emitEvent: false } makes no difference 
    }
  }

After just opening this form (component) the someField subscription triggers and therefore resets the otherField.

Even with [disabled]="this.formModel.isReadonly" instead of

if (this.formModel.isReadonly) {
      this.formGroup.disable(); // Passing { emitEvent: false } makes no difference 
    }

the valueChanges triggers. But the form was not changed at all.

Using v3.0.5 there is no problem, but using > v3.0.6 causes this problem.

I don't find a way to fix this problem by myself, so i created this issue.

Maybe you have tips or a fix for this issue.

Cheers! :-)

@4typen 4typen changed the title Initial disabled form triggers valueChanges Initially disabled form triggers valueChanges May 5, 2020
@alyalin
Copy link

alyalin commented Jul 17, 2020

I have the same problem. I want to disable the form, but all my components inside the form become ng-dirty by default. I'm using ngx-sub-form version 4.0.1

@4typen 4typen closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2023
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

Successfully merging a pull request may close this issue.

2 participants