optimistex / ngx-select-ex

Angular based replacement for select boxes
https://optimistex.github.io/ngx-select-ex/
MIT License
111 stars 42 forks source link

How can I do some job in between selecting/removing an item and when when the item is actually added/removed #178

Closed loadingx86 closed 4 years ago

loadingx86 commented 4 years ago

How can I do some job in between selecting/removing an item and when when the item is actually added/removed ?

Some kind of before action / preventDefault ?

optimistex commented 4 years ago

@loadingx86 Please, make more clear example. Most probably you are trying to go with a wrong way.

loadingx86 commented 4 years ago

ok, let's say I have some items in a dropdown for multiselect: items = [1, 2, 3 ,4 ,5]

and some rules that prevent items 2 and 3 to be selected notAllowed = [2, 3]

So, when I click "1" it is selected, and when I click "2" it is not selected and I get an alert() or something else

optimistex commented 4 years ago

@loadingx86 First thing is, keep latest selected item. When selected a forbidden item, then show an alert an select the last allowed.

loadingx86 commented 4 years ago

Can you provide some code ?

Also, if I have: [items]= [1, 2, 3 ,4 ,5] and selected: [1, 2, 3]

Now when I click x to remove "3": alert(you can not remove 3) (or some other job), and keep it selected ?

optimistex commented 4 years ago

@loadingx86 The example: https://stackblitz.com/edit/ngx-select-ex-scratch-issues-178?file=src%2Fapp%2Fapp.component.ts

loadingx86 commented 4 years ago

Thank you very much!