mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-09 17:16:36 +02:00
Return result count on search
This commit is contained in:
parent
6ebc0ea37a
commit
21f67b4289
|
@ -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`
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue