andreww1011 / filter-multi-select

Multiple select dropdown with filter jQuery plugin.
Other
28 stars 15 forks source link

How to listen for the clearBtn click? #7

Closed ericel closed 2 years ago

ericel commented 2 years ago

I want to listen to when the clear button of a selected button is clicked. Or even better, How can I listen for change that involves both selection and desellection?

I initialised the plugin as so: $('#job_city').filterMultiSelect(); This works fine, but I don't know how to go about listening for a change in the plugin

andreww1011 commented 2 years ago

Edit: see my comment below.

Hi Oj-

Currently, there is no functionality for this use case. This can be a future enhancement. Feel free to submit a pull request!

Best, -Andrew

andreww1011 commented 2 years ago

Hi Oj-

See v1.2.0.

The plugin now fires optionselected and optiondeselected events when an option is selected and deselected, respectively. You can poll the event object for the option label, value, and select element name.

$('#job_city').on('optionselected', function(e) {
  console.log(e.detail.label);
  console.log(e.detail.value);
  console.log(e.detail.name);
});
ericel commented 2 years ago

@andreww1011 THanks for the quick update. I will check it out and close the issue.