Mobius1 / Selectr

A lightweight, vanilla javascript select box replacement. No dependencies.
MIT License
312 stars 77 forks source link

selectr.deselect & selectr.change event value #30

Open kshaner opened 7 years ago

kshaner commented 7 years ago

There is a bug when using a clearable select and listening to the selectr.change event. It appears that select.deselect fires before selectr.change and the selectr.change argument provides the previous value and not an empty value. This is a problem for my use case because I'm using selectr to control external actions.

Sample:


const selectr = new Selectr(selectNode, {
    clearable: true,
    defaultSelected: false,
    searchable: true,
});

selectr.on('selectr.deselect', (option) => {
    // do something with option value
});

selectr.on('selectr.change', (option) => {
    // when fired after a selectr.deselect event, option is the previous value and not an empty value
});
reno1979 commented 5 years ago

With the latest pull request #93 this issue seems resolved

the events when I select an deselect:

change: value x // selected the value x change: null // deselected the value (cleared it) deselect: value x

stianrincon commented 3 years ago

Hi in the documentation it says that in order to allow unselect you need clearable=true and allowDeselect=true With this configuration everything works fine for me:

var selectr: any = document.getElementById(this.id);

var options = {
      allowDeselect: true,
      clearable: true,
    };

const selectorSelect = new Selectr(selectr, options)