fix(forms): clear parent when removing controls (#29517) - #29580
Conversation
When a control is removed from a FormGroup, or replaced by another control, that control's parent wasn't cleared. Apart from leaving the parent reference on the removed control, this also made it impossible for the control to react on its removal in an overridden setParent. This change introduces an unregisterControl method, symmetric to registerControl, which is called to clear a control's parent (set to null) when it's removed or replaced. PR Close #29517
|
The first failing check "ci/circleci:test" is a result of the public API change ( |
|
@fw-forms, please review, I'd be happy to address any issues and concerns :) |
|
Is there any particular reason the idea proposed by the PR is not valid (not taking into account CI checks)? |
|
Hi @itbrandonsilva, TLDR:
|
|
Hi @mbinic, thanks for creating this PR. I looked at the PR description and the issue that you refer to and I'd like to discuss it more. Currently when you call Thank you. |
|
Closing this PR for now as this change may cause some inconsistencies with other APIs (see #29580 (comment)). I think it'd be great to create a new PR to extend the |
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
PR Type
What is the current behavior?
When a control is removed from a
FormGroup(removeControl), or replaced by another control (setControl), that control's parent is not cleared, i.e. the removed control continues to reference the old parent.Issue Number: #29517
What is the new behavior?
When a control is removed or replaced, its
parentis set tonull.Does this PR introduce a breaking change?
If you were relying on the removed/replaced controls to retain the old parent reference, this would be a breaking change. This kind of usage seems like a hack, but to get it working, one could store the old parent reference prior to calling
removeControl/setControlor in an overriddensetParentmethod.Other information
Docs for the new
unregisterControlmethod have been added in the code file (forms/model.ts).