mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-20 22:46:33 +02:00
Update config/public method tests + minor tweaks"
This commit is contained in:
parent
6b0ec77a30
commit
1d133307bf
11
README.md
11
README.md
|
@ -230,6 +230,17 @@ Pass an array of objects:
|
|||
|
||||
<strong>Usage:</strong> The function that will sort choices before they are displayed (unless a user is searching). By default choices are sorted by alphabetical order.
|
||||
|
||||
<strong>Example:</strong>
|
||||
|
||||
```js
|
||||
// Sorting via length of label from largest to smallest
|
||||
const example = new Choices(element, {
|
||||
sortFilter: function(a, b) {
|
||||
return b.label.length - a.label.length;
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
### sortFields
|
||||
<strong>Type:</strong> `Array/String` <strong>Default:</strong>`['label', 'value']`
|
||||
|
||||
|
|
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
|
@ -520,9 +520,11 @@ export class Choices {
|
|||
disable() {
|
||||
this.passedElement.disabled = true;
|
||||
if(this.initialised) {
|
||||
this.input.disabled = true;
|
||||
this.containerOuter.classList.add(this.config.classNames.disabledState);
|
||||
this.containerOuter.setAttribute('aria-disabled', 'true');
|
||||
if(!this.containerOuter.classList.contains(this.config.classNames.disabledState)) {
|
||||
this.input.disabled = true;
|
||||
this.containerOuter.classList.add(this.config.classNames.disabledState);
|
||||
this.containerOuter.setAttribute('aria-disabled', 'true');
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -534,9 +536,11 @@ export class Choices {
|
|||
enable() {
|
||||
this.passedElement.disabled = false;
|
||||
if(this.initialised) {
|
||||
this.input.disabled = false;
|
||||
this.containerOuter.classList.remove(this.config.classNames.disabledState);
|
||||
this.containerOuter.removeAttribute('aria-disabled');
|
||||
if(this.containerOuter.classList.contains(this.config.classNames.disabledState)) {
|
||||
this.input.disabled = false;
|
||||
this.containerOuter.classList.remove(this.config.classNames.disabledState);
|
||||
this.containerOuter.removeAttribute('aria-disabled');
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -561,6 +565,8 @@ export class Choices {
|
|||
|
||||
if(results && results.length) {
|
||||
this.containerOuter.classList.remove(this.config.classNames.loadingState);
|
||||
const filter = this.config.sortFilter;
|
||||
|
||||
results.forEach((result, index) => {
|
||||
// Select first choice in list if single select input
|
||||
if(index === 0 && this.passedElement.type === 'select-one') {
|
||||
|
|
|
@ -55,7 +55,10 @@ describe('Choices', function() {
|
|||
expect(this.choices.config.delimiter).toEqual(jasmine.any(String));
|
||||
expect(this.choices.config.paste).toEqual(jasmine.any(Boolean));
|
||||
expect(this.choices.config.search).toEqual(jasmine.any(Boolean));
|
||||
expect(this.choices.config.flip).toEqual(jasmine.any(Boolean));
|
||||
expect(this.choices.config.regexFilter).toEqual(null);
|
||||
expect(this.choices.config.sortFilter).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.config.sortFields).toEqual(jasmine.any(Array) || jasmine.any(String));
|
||||
expect(this.choices.config.placeholder).toEqual(jasmine.any(Boolean));
|
||||
expect(this.choices.config.placeholderValue).toEqual(null);
|
||||
expect(this.choices.config.prependValue).toEqual(null);
|
||||
|
@ -82,8 +85,11 @@ describe('Choices', function() {
|
|||
expect(this.choices.hideDropdown).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.toggleDropdown).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.setValue).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.setValueByChoice).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.setChoices).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.clearValue).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.disable).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.enable).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.ajax).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.clearInput).toEqual(jasmine.any(Function));
|
||||
expect(this.choices.clearInput).toEqual(jasmine.any(Function));
|
||||
|
|
Loading…
Reference in a new issue