If the user initializes the library with the following options
const townsSelect= new Choices('#towns', {
searchFloor: 0
})
and then clears the input field using the backspace, no search event is triggered.
search event is triggered with empty string value
at line 933 of https://github.com/jshjohnson/Choices/blob/master/src/scripts/choices.js
change
...
if (value && value.length >= searchFloor) {...}
...
to
...
if (value !== null && typeof value !=="undefined" && value.length >= searchFloor) {...}
...
Logic in _onKeyUp handler should be tweaked as well to call _handleSearch with empty value.
https://github.com/jshjohnson/Choices/blob/master/src/scripts/choices.js#L1207
Fast and hard fix:
townsSelect.input.addEventListener('keyup', function () {
console.log(this.value);
});
@tinovyatkin @jshjohnson is this something you guys have on your radar? are you accepting PRs?
I'm using this hard coded workaround for choices.js 9.0.1 for now.
townSelect.input.element.addEventListener('keyup', (event) => {
if ((event.which === 8 || event.which === 46) && event.target.value === '' && townSelect.config.searchFloor === 0) {
// Trigger search event
var resultCount = townSelect.config.searchChoices ? townSelect._searchChoices(event.target.value) : 0
townSelect.passedElement.triggerEvent('search', {
value: event.target.value,
resultCount: resultCount
})
}
})