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

formArray's valueChange is not triggered when the length is decreasing #3250

Closed
dc-p8 opened this issue Mar 31, 2022 · 1 comment
Closed
Labels

Comments

@dc-p8
Copy link

dc-p8 commented Mar 31, 2022

Description
When you change the length of a fieldArray, the valueChange observable associated to the formArray control is only triggered when the count is increasing but not when the length decrease.

Minimal Reproduction
https://stackblitz.com/edit/angular-7mcxsf?file=src/app/app.component.ts

Change the count from 3 to 4, 4 to 5, you will see in the console that the valueChange is triggered accordingly.
But when you set the counter from 5 to 4 and 4 to 3, nothing happens in the console.

Workaround
Just after setting the new model, you can put this:

setTimeout(() => {
    this.form.get('investments').updateValueAndValidity({ onlySelf: true, emitEvent: true });
    // (<any>this.form)._updateTreeValidity({ emitEvent: true }); // more generic, also works
});

The problem is that the valueChange will be triggered 2 times when increasing the count (even when using distinctUntilChanged)

Your Environment

  • Angular version: 13.3.1
  • Formly version: 6.0.0-next.9
@aitboudad
Copy link
Member

This issue has been fixed and released as part of v5.12.1 release.

Please let us know, in case you are still encountering a similar issue/problem.
Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants