ng-select icon indicating copy to clipboard operation
ng-select copied to clipboard

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

Open akaegi opened this issue 6 years ago • 3 comments

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.

akaegi avatar Nov 04 '20 13:11 akaegi

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 :fireworks:

github-actions[bot] avatar Jan 04 '21 00:01 github-actions[bot]

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.

scarela avatar Jan 07 '21 16:01 scarela

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.

varnastadeus avatar Jan 09 '21 11:01 varnastadeus