bluzky / nice-select2

A lightweight vanilla javascript library that replaces native select elements with customizable dropdowns
https://bluzky.github.io/nice-select2/
MIT License
361 stars 60 forks source link

FR: add event when you open/close the niceselect #33

Closed hiasl closed 1 year ago

hiasl commented 2 years ago

Hi, We are using both single and multiselects and I want to submit a form when something changes. For single selects this can easily be done by listening to the change event of the original select, but for multiselects this would be triggered on the first change, but instead I want to react once the pulldown is closed. I should actually monitor if something has changed while the nice-select is opened and trigger the submission once the niceselect is closed.

Could you please add an event when the nice select opens and another event when it gets closed.

And if you want to be super handy you could fire an event for both single and multiselects if something has changed on close. That would, for example, prevent event triggering when the same option is selected and unselected again in a multiselect and closed.

Thanks!

Tsjippy commented 1 year ago

You can now do this: document.querySelector("#someSelect").addEventListener("modalclose", ev=>console.log(ev.target)) document.querySelector("#someSelect").addEventListener("modalopen", ev=>console.log(ev.target))