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

Two ng-select elements bound to same form control are not in sync #1791

Closed
akaegi opened this issue Nov 4, 2020 · 3 comments
Closed

Two ng-select elements bound to same form control are not in sync #1791

akaegi opened this issue Nov 4, 2020 · 3 comments

Comments

@akaegi
Copy link

akaegi commented Nov 4, 2020

Describe the bug
Given two ng-select elements that are both bound to the same form control (reactive forms)
when the user selects an item in one of the ng-select elements
then I expect the second ng-select element to be updated accordingly.

Reproducbile example
https://stackblitz.com/edit/angular-894pxt

To Reproduce
Steps to reproduce the behavior (if example is not provided):

  1. Select entry in first ng-select
  2. Second ng-select is not updated

Expected behavior
Second ng-select shows the same selected entry.

@github-actions
Copy link

github-actions bot commented Jan 4, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions 🎆

@github-actions github-actions bot added the stale label Jan 4, 2021
@Evand3r
Copy link

Evand3r commented Jan 7, 2021

No solution for this yet, had to work around it by patching the value to the formControl manually in a change event. Really annoying, but oh well.

@github-actions github-actions bot removed the stale label Jan 8, 2021
@varnastadeus
Copy link
Member

It works as expected, you can confirm that replacing it with simple selects and you will get identical behaviour:

 <select 
                   (ngModelChange)="showConfirm(confirmation)"
                   placeholder="Select age"
                   formControlName="age">
                   <option *ngFor="let age of ages" [value]="age.value">{{ age.label }}</option>
        </select>
        <select 
                   (ngModelChange)="showConfirm(confirmation)"
                   placeholder="Select age"
                   formControlName="age">
                   <option *ngFor="let age of ages" [value]="age.value">{{ age.label }}</option>
        </select>

AFAIK, you can't have controls with the same formControlName. Please refer to StackOverflow to solve your problem.

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

No branches or pull requests

3 participants