Selectr
Selectr copied to clipboard
selectr.deselect & selectr.change event value
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
});
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
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)