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**. **Usage:** Triggered each time an item is added/removed **by a user**.
### search ### search
**Arguments:** `value` **Arguments:** `value`, `resultCount`
**Input types affected:** `select-one`, `select-multiple` **Input types affected:** `select-one`, `select-multiple`
**Usage:** Triggered when a user types into an input to search choices. **Usage:** Triggered when a user types into an input to search choices.
### showDropdown ### showDropdown
**Arguments:** - **Arguments:** -
**Input types affected:** `select-one`, `select-multiple` **Input types affected:** `select-one`, `select-multiple`

View file

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

View file

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