-
Notifications
You must be signed in to change notification settings - Fork 621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow triggering of 'search' event when clearing the input field #630
Comments
Logic in 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
})
}
}) |
8 tasks
8 tasks
10 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
current behaviour
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.expected behaviour
search
event is triggered with empty string valueproposed fix
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) {...} ...
The text was updated successfully, but these errors were encountered: