Return result count on search

This commit is contained in:
Josh Johnson 2017-07-31 16:17:03 +01:00
parent 6ebc0ea37a
commit 21f67b4289
3 changed files with 13 additions and 3 deletions

View file

@ -574,14 +574,14 @@ example.passedElement.addEventListener('addItem', function(event) {
**Usage:** Triggered each time an item is added/removed **by a user**.
### search
**Arguments:** `value`
**Arguments:** `value`, `resultCount`
**Input types affected:** `select-one`, `select-multiple`
**Usage:** Triggered when a user types into an input to search choices.
### showDropdown
**Arguments:** -
**Arguments:** -
**Input types affected:** `select-one`, `select-multiple`

View file

@ -1416,7 +1416,11 @@ class Choices {
this.store.dispatch(
filterChoices(results)
);
return results.length;
}
return 0;
}
/**
@ -1437,14 +1441,16 @@ class Choices {
if (this.input === document.activeElement) {
// Check that we have a value to search and the input was an alphanumeric character
if (value && value.length >= this.config.searchFloor) {
let resultCount = 0;
// Check flag to filter search input
if (this.config.searchChoices) {
// Filter available choices
this._searchChoices(value);
resultCount = this._searchChoices(value);
}
// Trigger search event
triggerEvent(this.passedElement, 'search', {
value,
resultCount
});
} else if (hasUnactiveChoices) {
// Otherwise reset choices to active

View file

@ -352,6 +352,10 @@
removeItemButton: true,
});
multipleCancelButton.passedElement.addEventListener('search', (e) => {
console.log(e.detail);
});
/* Use label on event */
var choicesSelect = new Choices('#choices-multiple-labels', {
removeItemButton: true,