Selectr icon indicating copy to clipboard operation
Selectr copied to clipboard

selectr.deselect & selectr.change event value

Open kshaner opened this issue 6 years ago • 2 comments

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
});

kshaner avatar Aug 22 '17 15:08 kshaner

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

reno1979 avatar Feb 26 '19 22:02 reno1979

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)

stianrincon avatar Apr 21 '21 22:04 stianrincon