angular-ui / ui-select

AngularJS-native version of Select2 and Selectize
MIT License
3.26k stars 1.82k forks source link

onSelect and onRemove don't trigger #2031

Open DarkIsDude opened 7 years ago

DarkIsDude commented 7 years ago

Bug description:

on-remove and on-select never trigger

Link to minimally-working plunker that reproduces the issue:

http://plnkr.co/edit/CtSiLw60WnfcNL0h4cqp?p=preview [edit 06/09/2017] With multiple example http://plnkr.co/edit/V2cVQojYpZACNrMUaaRC?p=preview

Version of Angular, UI-Select, and Bootstrap/Select2/Selectize CSS

Angular: 1.5.0

UI-Select: 0.19.8

Bootstrap/Select2/Selectize CSS (if applicable): See in plunker

ThibaultChauvidan commented 7 years ago

Actually only onRemove has issue, I modify the plnkr and onSelect work fine. It's just you can't use console log in the HTML code. I also add ngChange and onChange, it's seem that ngChange work fine but not onChange Hope it helped

DarkIsDude commented 7 years ago

Thanks for your help. You are right, it seem that just onRemove has issue. I will try a PR maybe :).

Jefiozie commented 7 years ago

Thanks for the PR. I think this needs some extra digging, when using the onRemove with the multiple it is working. So it look like a specific single select problem. Also is the onRemove not working in general or is it just with the combination of allow-clear?

DarkIsDude commented 7 years ago

How can I remove an element without the allow-clear directive in single mode? I have updated the plnkr for add multiple example. You are right, with the multiple attribute, onRemove work.

http://plnkr.co/edit/V2cVQojYpZACNrMUaaRC?p=preview

augustjared1 commented 6 years ago

I have a fix!!! My coworker found it based on our old code! the ctrl.clear (line 541 in select.js) function should read like below

ctrl.clear = function ($event) { var itemRemove = ctrl.selected; ctrl.select(undefined); $event.stopPropagation(); ctrl.focusser[0].focus(); ctrl.onRemoveCallback($scope, { $item: itemRemove }); }; The bolded lines are missing after the update and when I put them back in -- it worked just fine. Hope this helps!

ganholete commented 5 years ago

+1