mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-09 00:56:34 +02:00
Ability to pass function to no choice/result notices
This commit is contained in:
parent
473f010998
commit
ccfad3cf9b
|
@ -341,18 +341,18 @@ const example = new Choices(element, {
|
|||
**Usage:** The text that is shown whilst choices are being populated via AJAX.
|
||||
|
||||
### noResultsText
|
||||
**Type:** `String` **Default:** `No results found`
|
||||
**Type:** `String/Function` **Default:** `No results found`
|
||||
|
||||
**Input types affected:** `select-one`, `select-multiple`
|
||||
|
||||
**Usage:** The text that is shown when a user's search has returned no results.
|
||||
**Usage:** The text that is shown when a user's search has returned no results. Optionally pass a function returning a string.
|
||||
|
||||
### noChoicesText
|
||||
**Type:** `String` **Default:** `No choices to choose from`
|
||||
**Type:** `String/Function` **Default:** `No choices to choose from`
|
||||
|
||||
**Input types affected:** `select-multiple`
|
||||
|
||||
**Usage:** The text that is shown when a user has selected all possible choices.
|
||||
**Usage:** The text that is shown when a user has selected all possible choices. Optionally pass a function returning a string.
|
||||
|
||||
### itemSelectText
|
||||
**Type:** `String` **Default:** `Press to select`
|
||||
|
|
|
@ -412,9 +412,17 @@ class Choices {
|
|||
this._highlightChoice();
|
||||
} else {
|
||||
// Otherwise show a notice
|
||||
const dropdownItem = this.isSearching ?
|
||||
this._getTemplate('notice', this.config.noResultsText) :
|
||||
this._getTemplate('notice', this.config.noChoicesText);
|
||||
let dropdownItem;
|
||||
let notice;
|
||||
|
||||
if (this.isSearching) {
|
||||
notice = isType('Function', this.config.noResultsText) ? this.config.noResultsText() : this.config.noResultsText;
|
||||
dropdownItem = this._getTemplate('notice', notice);
|
||||
} else {
|
||||
notice = isType('Function', this.config.noChoicesText) ? this.config.noChoicesText() : this.config.noChoicesText;
|
||||
dropdownItem = this._getTemplate('notice', notice);
|
||||
}
|
||||
|
||||
this.choiceList.appendChild(dropdownItem);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue