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

fix(forms): Multiple formControlName directives using the same FormControl do not stay in sync #53668

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AnthonyFr75
Copy link
Contributor

@AnthonyFr75 AnthonyFr75 commented Dec 20, 2023

When other controls share the same form control reference

Fixes #50957

@AnthonyFr75 AnthonyFr75 force-pushed the my-fix-branch-for-51239 branch 2 times, most recently from 5b832d4 to 70061ea Compare December 20, 2023 21:10
* @private
*/
private _syncControlValuesUnderSameFormGroup(newValue: any): void {
if (this._parent instanceof FormGroupDirective) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might also want to supporte the FormArrayDirective here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took in account

private _syncControlValuesUnderSameFormGroup(newValue: any): void {
if (this._parent instanceof FormGroupDirective) {
this._parent.directives.forEach((dir: FormControlName) => {
const sameControlReference = dir!.control === this.control;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the non null assertion isn't necessary here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

took in account

…ntrol do not stay in sync

When other controls share the same form control reference

Fixes angular#51239
@AndrewKushnir AndrewKushnir requested review from dylhunn and removed request for AndrewKushnir January 2, 2024 19:05
@ngbot ngbot bot added this to the Backlog milestone Jan 17, 2024
@dylhunn
Copy link
Contributor

dylhunn commented Jan 17, 2024

I agree in principle that this would be a nice fix, but it's certain to be a significant breaking change (as is frequently the case with Forms changes). I could run a Google global presubmit to find out how bad the breakage is though.

@IbenTesara
Copy link

I agree in principle that this would be a nice fix, but it's certain to be a significant breaking change (as is frequently the case with Forms changes). I could run a Google global presubmit to find out how bad the breakage is though.

Is there any news on this?

We're currently trying to refactor a part of our application that would require this fix. Nothing really pressing, so no need to hurry here, but it would help us out tremendously!

@JeanMeche
Copy link
Member

JeanMeche commented May 18, 2024

We discussed recently with @dylhunn landing some breaking changes behind flags, this could be one of them. (#55761 is another one for example).

Let us investigate this so we can land several forms improvements in the upcoming versions.

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

Successfully merging this pull request may close these issues.

FormControls are not usable in multiple formGroups
4 participants