mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-20 22:46:33 +02:00
Configurable sorting fields
This commit is contained in:
parent
63bef1ee0e
commit
b7484612eb
|
@ -41,6 +41,7 @@ A lightweight, configurable select box/text input plugin. Similar to Select2 and
|
|||
search: true,
|
||||
flip: true,
|
||||
regexFilter: null,
|
||||
sortFields: ['label', 'value'],
|
||||
placeholder: true,
|
||||
placeholderValue: null,
|
||||
prependValue: null,
|
||||
|
@ -221,6 +222,13 @@ Pass an array of objects:
|
|||
|
||||
<strong>Usage:</strong> A filter that will need to pass for a user to successfully add an item.
|
||||
|
||||
### sortFields
|
||||
<strong>Type:</strong> `Array/String` <strong>Default:</strong>`['label', 'value']`
|
||||
|
||||
<strong>Input types affected:</strong>`select-one`, `select-multiple`
|
||||
|
||||
<strong>Usage:</strong> Specify which fields should be used for sorting.
|
||||
|
||||
### placeholder
|
||||
<strong>Type:</strong> `Boolean` <strong>Default:</strong>`true`
|
||||
|
||||
|
|
4
assets/scripts/dist/choices.min.js
vendored
4
assets/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -38,6 +38,7 @@ export class Choices {
|
|||
search: true,
|
||||
flip: true,
|
||||
regexFilter: null,
|
||||
sortFields: ['label', 'value'],
|
||||
placeholder: true,
|
||||
placeholderValue: null,
|
||||
prependValue: null,
|
||||
|
@ -884,8 +885,9 @@ export class Choices {
|
|||
if(newValue.length >= 1 && newValue !== currentValue + ' ') {
|
||||
const haystack = this.store.getChoicesFiltedBySelectable();
|
||||
const needle = newValue;
|
||||
const keys = isType('Array', this.config.sortFields) ? this.config.sortFields : [this.config.sortFields];
|
||||
const fuse = new Fuse(haystack, {
|
||||
keys: ['label', 'value'],
|
||||
keys: keys,
|
||||
shouldSort: true,
|
||||
include: 'score',
|
||||
});
|
||||
|
|
|
@ -225,7 +225,9 @@
|
|||
});
|
||||
});
|
||||
|
||||
var example10 = new Choices('#choices-14').ajax(function(callback) {
|
||||
var example10 = new Choices('#choices-14', {
|
||||
sortFields: 'value'
|
||||
}).ajax(function(callback) {
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('get', 'https://restcountries.eu/rest/v1/all', true);
|
||||
request.onreadystatechange = function() {
|
||||
|
|
Loading…
Reference in a new issue