Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

FormControls are not usable in multiple formGroups #50957

Copy link
Copy link
Open
@enrique-lozano

Description

@enrique-lozano
Issue body actions

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

forms

Is this a regression?

Yes

Description

Right now using the same formControls in multiple formGroups is not possible. From the developer's point of view, I think it would be more intuitive in this case that the controls were synchronized. It seems that it only changes the value in the last formGroup that the controls are assigned to.

Example:

userControl = new FormControl('');
passControl = new FormControl('');

form1 = new FormGroup({
 user1: this.userControl,
 pass1: this.userControl
});

form2 = new FormGroup({
  user2: this.userControl,
  pass2: this.userControl
});

constructor(){
     this.form1.valueChanges.subscribe((res) => {
       // Never enter here:
       console. log('FORM1 Changes');
     });

     this.form2.valueChanges.subscribe((res) => {
       console. log('FORM2 Changes');
     });
}

In the HTML:

<form [formGroup]="form1">
     <!---- If you type here, the console prints 'FORM2 Changes' ------>
     <input type="text" matInput formControlName="user1" placeholder="user in form 1">
     <input type="text" matInput formControlName="pass1" placeholder="pass in form 1">
</form>


<form [formGroup]="form2">
     <input type="text" matInput formControlName="user2" placeholder="user in form 2">
     <input type="text" matInput formControlName="pass2" placeholder="pass in form 2">
</form>

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

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

Angular CLI: 15.2.8
Node: 16.15.1
Package Manager: npm 8.14.0
OS: win32 x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1502.8
@angular-devkit/build-angular   15.2.8
@angular-devkit/core            15.2.8
@angular-devkit/schematics      15.2.8
@angular/cli                    15.2.8
@schematics/angular             15.2.8
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsforms: Controls APIIssues related to AbstractControl, FormControl, FormGroup, FormArray.Issues related to AbstractControl, FormControl, FormGroup, FormArray.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.