snapappointments / bootstrap-select

:rocket: The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more.
https://developer.snapappointments.com/bootstrap-select/
MIT License
9.84k stars 2.72k forks source link

Re-Rendering breaks event listeners #2824

Open Ov-ille opened 1 year ago

Ov-ille commented 1 year ago

I'm using selectpickers that are updated through javascript based on other selections (enabled/disabled, added/deleted options). I have found that sometimes this is only possible by destroying and rerendering the selectpicker, which works fine.

However, now I have noticed that this seems to break eventlisteners based on the selectpickers.

I have created a simple example here: https://jsfiddle.net/L23zr09u/

Both dropdowns are supposed to print somethign to the console, when the dropdown opens. For the first one this works, for the second one that gets destroyed and rendered, there is no response.

Am I doing something wrong or is this a bug? And is there a way around it?

plocket commented 1 year ago

Looks like if you create the event listeners inside document...ready, the second one will still log: https://jsfiddle.net/qxws2075/. Not sure why.