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