Enable() method

This commit is contained in:
Josh Johnson 2016-08-02 21:10:53 +01:00
parent e497999841
commit 5817ce3a0f
4 changed files with 48 additions and 7 deletions

View file

@ -383,20 +383,47 @@ choices.disable();
### setChoices(choices, value, label);
<strong>Input types affected:</strong> `select-one`, `select-multiple`
<strong>Usage:</strong> Set choices of select input via an array of objects, a value name and a label name. This behaves exactly the same as passing items via the `choices` option but can be called after initialising Choices.
<strong>Usage:</strong> Set choices of select input via an array of objects, a value name and a label name. This behaves the same as passing items via the `choices` option but can be called after initialising Choices. This can also be used to add groups of choices (see example 2);
<strong>Example:</strong>
<strong>Example 1:</strong>
```js
const choices = new Choices(element);
const example = new Choices(element);
choices.setChoices([
example.setChoices([
{value: 'One', label: 'Label One', disabled: true},
{value: 'Two', label: 'Label Two' selected: true},
{value: 'Three', label: 'Label Three'},
], 'value', 'label');
```
<strong>Example 2:</strong>
```js
const example = new Choices(element);
example.setChoices([{
label: 'Group one',
id: 1,
disabled: false,
choices: [
{value: 'Child One', label: 'Child One', selected: true},
{value: 'Child Two', label: 'Child Two', disabled: true},
{value: 'Child Three', label: 'Child Three'},
]
},
{
label: 'Group two',
id: 2,
disabled: false,
choices: [
{value: 'Child Four', label: 'Child Four', disabled: true},
{value: 'Child Five', label: 'Child Five'},
{value: 'Child Six', label: 'Child Six'},
]
}], 'value', 'label');
```
### getValue(valueOnly)
<strong>Input types affected:</strong> `text`, `select-one`, `select-multiple`

File diff suppressed because one or more lines are too long

View file

@ -517,7 +517,7 @@ export class Choices {
}
/**
* Disable
* Disable interaction with Choices
* @return {Object} Class instance
* @public
*/
@ -530,6 +530,19 @@ export class Choices {
return this;
}
/**
* Enable interaction with Choices
* @return {Object} Class instance
*/
enable() {
this.passedElement.disabled = false;
if(this.initialised) {
this.input.disabled = false;
this.containerOuter.classList.remove(this.config.classNames.disabledState);
}
return this;
}
/**
* Populate options via ajax callback
* @param {Function} fn Passed

View file

@ -250,6 +250,7 @@
});
var example12 = new Choices('#choices-15', {
search: false,
choices: [
{value: 'One', label: 'Label One'},
{value: 'Two', label: 'Label Two', disabled: true},