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

Nb-Select not emitting change event #948

Closed
itkachyshyn opened this issue Oct 26, 2018 · 29 comments · Fixed by #1009
Closed

Nb-Select not emitting change event #948

itkachyshyn opened this issue Oct 26, 2018 · 29 comments · Fixed by #1009
Assignees
Milestone

Comments

@itkachyshyn
Copy link

Nb-Select not emitting event when used with [ngModel]

I'm submitting a bug report

Issue description

Current behavior:
Nb-Select does not emit (selectChange) or (ngModelChange) event when using observables with ngModel.

<nb-select (selectedChange)="onChange($event)" (ngModelChange)="onChange($event)"
    [ngModel]="selectedLocationUnitGroupId$ | async">
    <nb-option *ngFor="let option of locationUnitGroups$ | async" [value]="option.id">
        {{ option.type }}
    </nb-option>
 </nb-select>

Expected behavior:
I want nb-select to emit (selectChange) or (ngModelChange) event every time user selects an option

Any ideas how to fix it?

@pdomala
Copy link

pdomala commented Nov 4, 2018

I am having the same issue. Nb-select does not work if the options are generated using ngFor and observables. Hardcoding nb-option tags works fine.

@mckuok
Copy link

mckuok commented Nov 4, 2018

Anyone have a solution?
After some investigation, I note that in the property options._results, the ones generated by ngFor does not have an observer under selectionChange. However I don't know how to fix it. Hope that helps.

@mushu8
Copy link

mushu8 commented Nov 6, 2018

up plz :

<nb-select placeholder="Menu" (selectedChange)="onMenuItemSelected($event)">
    <nb-option-group *ngFor="let rootMenu of rootMenus" title="{{rootMenu.rootMenu.name}}">
        <nb-option *ngFor="let menu of rootMenu.menus" value="{{menu.id}}">{{menu.name}}</nb-option>
    </nb-option-group>
</nb-select>

data :

[
  {
    "rootMenu":{"id":0,"name":"A"},
    "menus": [
      {"id":3,"name":"B"},
      {"id":2,"name":"C"}
    ]
  }
]

@Tibing
Copy link
Member

Tibing commented Nov 6, 2018

Hi guys, the issue will be resolved in the nearest future.

@mushu8
Copy link

mushu8 commented Nov 6, 2018

Thanks @Tibing
How near please ? hours ? days ? weeks ?
I'm currently on a client project and start thinking of ng-select but it will break the ui … :(

@Tibing
Copy link
Member

Tibing commented Nov 6, 2018

Hi @mushu8, hope I'll be done this week, and next release version will be published next week

@mushu8
Copy link

mushu8 commented Nov 6, 2018

ok thanks 👍

@thomasreji
Copy link

am facing the same issue too. When is the plan to release?

@nnixaa nnixaa added this to the 3.0.1 milestone Nov 19, 2018
@issue-sh issue-sh bot added Sprint and removed Backlog labels Nov 22, 2018
@gaspardip
Copy link

any workaround for this in the meantime?

@mushu8
Copy link

mushu8 commented Nov 28, 2018

I’ve integrated ng-select

@anupam42
Copy link

anupam42 commented Feb 13, 2019

@pdomala Have u got any solutions for ur issue because i am facing the same issue

@AsmaGargouri
Copy link

We are facing the same problem. Is there any solution yet please ?

@nu5rim3
Copy link

nu5rim3 commented Jun 25, 2019

any update?

@t33zy
Copy link

t33zy commented Jun 25, 2019

Anyone got this issue solved? Please help

@chadirahme
Copy link

still not working !!

@ruodeng
Copy link

ruodeng commented Aug 18, 2019

my solution is that, I have a pickupAddress which type is string, but put it into a temp array, only contain one value, and loop this array can work.

         <div class="form-group" *ngFor="let bc of tempPickupAddress">
                  <nb-select   *ngIf="canEdit" fullWidth [(selected)]="bc" (selectedChange)="onUpdatePickupAddress($event)" >
                    <nb-option-group   *ngFor="let pick of pickupAddress">
                    <nb-option  [value]="pick._id"> {{pick.unit}} {{ pick.street }}</nb-option>
                    </nb-option-group>
                  </nb-select> 
            </div>

related component

... 
tempPickupAddress = [null];
...
// In the ajax
    this.tempPickupAddress = [data.bulkOrder.pickupAddress];
...
// Update on select change.
 onUpdatePickupAddress(event) {
    this.bulkOrder.pickupAddress = event;
  }

@bkstorm
Copy link

bkstorm commented Oct 12, 2019

I have the same problem. This issue has not been solved.

@AngelCareaga
Copy link

Solved this...

HTML

<nb-select placeholder="Seleccionar Talla" [(selected)]="selectedItemTalla" filled status="warning">
          <nb-option *ngFor="let talla of tallas" (click)="cambiaTalla(talla.sigla)" [value]="talla.sigla">{{talla.sigla}} <span style="opacity: 0.4 !important;">&nbsp;({{talla.quantity}} Disp)</span></nb-option>
        </nb-select>

AND TS

cambiaTalla(talla){
    console.log(talla);
  }

The Key is in the (click), cheers!!!

@GreedyA1
Copy link

same issue with selectedChange. @AngelCareaga click doesn't work for me. it just simply doesn't trigger anything.

@codeztech-atique
Copy link

Same issue

@codeztech-atique
Copy link

Same issue @AngelCareaga does not work form me -
<nb-select class="optionsData" [(selected)]="this.statusData">
<nb-option *ngFor="let status of tagsAPIStatus" (change)="selectedChange(status)" [value]="this.statusData === status ? status : ''">
 {{status}}

selectedChange(e) {
console.log(e);
this.statusData = e;
}

Not working

@Nisha-Yadav-1
Copy link

Solved this...

HTML

<nb-select placeholder="Seleccionar Talla" [(selected)]="selectedItemTalla" filled status="warning">
          <nb-option *ngFor="let talla of tallas" (click)="cambiaTalla(talla.sigla)" [value]="talla.sigla">{{talla.sigla}} <span style="opacity: 0.4 !important;">&nbsp;({{talla.quantity}} Disp)</span></nb-option>
        </nb-select>

AND TS

cambiaTalla(talla){
    console.log(talla);
  }

The Key is in the (click), cheers!!!

This would create too many event listeners. This could create a performance issue if used on multiple select box on single page and if each select box contains lots of options.

@aritrabasu104
Copy link

aritrabasu104 commented Apr 15, 2020

@AngelCareaga @Nisha-Yadav-1
We can use selectedChange event like this
<nb-select (selectedChange)="doWhatEverOnChange()" formControlName="transmissionType">

@JoseSpx
Copy link

JoseSpx commented Jul 13, 2020

Same issue, please fixed it. thanks

@JoseSpx
Copy link

JoseSpx commented Jul 13, 2020

Solved this.
(selectedChange)="selectedClientChange($event)"
Send the "$event", and the method will receive the value selected.

@westrindade
Copy link

Eu estou usando o translate...
Quando altero o idioma as opções de seleção são alteradas corretamente, mas se ja estiver selecionado uma opção, ele não altera ela, mas ao clicar no componente ele altera.
Podem me ajudar?

@amarnandeshwar786
Copy link

amarnandeshwar786 commented Jan 3, 2022

I am facing the following UI issue in nb-select, is anyone have a solution then please help to resolve this issue

image

@anupam42
Copy link

I am facing the following UI issue in nb-select, is anyone have a solution then please help to resolve this issue

image

@amarnandeshwar786 might with css class overlapping issue. Check some margin top added.

@nikita-fuchs
Copy link

None of the proposed solutions here work. The only thing you can do is have it directly put into the corresponding form control under its formcontrol name, and then listen to its changes.

like:

<form [formGroup]="tarifSchemaDataForm"> .... and then further below...

 <nb-select *ngSwitchCase="'options'"  [selected]="" fullWidth="true" placeholder="{{field.label}}" formControlName="{{field.name}}" nbPopover="{{field.helpMessage}}" nbPopoverTrigger="noop" nbPopoverContext="{{field.name}}">
            <nb-option *ngFor="let option of field.options | keyvalue" value="{{ option.key }}" > <div class="numberCircle">{{option.key}}</div><span style="white-space:nowrap;"> &nbsp;&nbsp;{{option.value }}</span></nb-option>
          </nb-select>

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

Successfully merging a pull request may close this issue.