[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Child Form Groups Don't Receive Updated _onCollectionChange() When FormGroupDirective Seeds Parent with Callback #59097

Open
newmankyle opened this issue Dec 7, 2024 · 0 comments

Comments

@newmankyle
Copy link

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

No

Description

We rely on _onCollectionChange() to notify its FormGroupDirective to re-bind its FormControlName directives, and FormGroup is smart enough to propagate its _onCollectionChange() callback so that Child FormGroups can notify too. This happens in two scenarios

  1. When we first initialize the FormGroup (the constructor calls _setupControl() which binds _onCollectionChange() to the children
  2. When we call registerControl (and associated methods)

The problem is with scenario 1: we may seed each child control with a default callback (an empty function) on init, but we don't propagate a new callback when we eventually bind the FormGroup to a FormGroupDirective. The child FormGroups are still working with the 'default' one. Furthermore the api is private so I don't see any way to fix this on the user side.

If we have a scenario where a child form group adds controls dynamically, and some of those controls are FormControlName directives (see stackblitz), then we fail to trigger _updateDOMValue() on the parent FormGroupDirective. The FormControlName directives are left with orphaned form controls.

Ideally, _registerOnCollectionChange() would cascade to its children (or maybe just call _setupControls() again).

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-iatn8h?file=src%2Fbroken-form.ts

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 18.2.0
Node: 20.11.1
Package Manager: yarn 4.4.0
OS: linux x64

Angular: 18.2.0
... animations, cdk, cli, common, compiler, compiler-cli, core
... forms, language-service, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1802.0
@angular-devkit/build-angular   18.2.0
@angular-devkit/core            18.2.0
@angular-devkit/schematics      18.2.0
@angular/flex-layout            14.0.0-beta.41
@schematics/angular             18.2.0
ng-packagr                      18.2.0
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.10

Anything else?

No response

@ngbot ngbot bot added this to the needsTriage milestone Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants