Ability to pass function to no choice/result notices

This commit is contained in:
Josh Johnson 2017-02-09 13:49:30 +00:00
parent 473f010998
commit ccfad3cf9b
2 changed files with 15 additions and 7 deletions

View file

@ -341,18 +341,18 @@ const example = new Choices(element, {
**Usage:** The text that is shown whilst choices are being populated via AJAX. **Usage:** The text that is shown whilst choices are being populated via AJAX.
### noResultsText ### noResultsText
**Type:** `String` **Default:** `No results found` **Type:** `String/Function` **Default:** `No results found`
**Input types affected:** `select-one`, `select-multiple` **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 ### noChoicesText
**Type:** `String` **Default:** `No choices to choose from` **Type:** `String/Function` **Default:** `No choices to choose from`
**Input types affected:** `select-multiple` **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 ### itemSelectText
**Type:** `String` **Default:** `Press to select` **Type:** `String` **Default:** `Press to select`

View file

@ -412,9 +412,17 @@ class Choices {
this._highlightChoice(); this._highlightChoice();
} else { } else {
// Otherwise show a notice // Otherwise show a notice
const dropdownItem = this.isSearching ? let dropdownItem;
this._getTemplate('notice', this.config.noResultsText) : let notice;
this._getTemplate('notice', this.config.noChoicesText);
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); this.choiceList.appendChild(dropdownItem);
} }
} }