mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-03 06:22:25 +02:00
Enable() method
This commit is contained in:
parent
e497999841
commit
5817ce3a0f
35
README.md
35
README.md
|
@ -383,20 +383,47 @@ choices.disable();
|
||||||
### setChoices(choices, value, label);
|
### setChoices(choices, value, label);
|
||||||
<strong>Input types affected:</strong> `select-one`, `select-multiple`
|
<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
|
```js
|
||||||
const choices = new Choices(element);
|
const example = new Choices(element);
|
||||||
|
|
||||||
choices.setChoices([
|
example.setChoices([
|
||||||
{value: 'One', label: 'Label One', disabled: true},
|
{value: 'One', label: 'Label One', disabled: true},
|
||||||
{value: 'Two', label: 'Label Two' selected: true},
|
{value: 'Two', label: 'Label Two' selected: true},
|
||||||
{value: 'Three', label: 'Label Three'},
|
{value: 'Three', label: 'Label Three'},
|
||||||
], 'value', 'label');
|
], '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)
|
### getValue(valueOnly)
|
||||||
<strong>Input types affected:</strong> `text`, `select-one`, `select-multiple`
|
<strong>Input types affected:</strong> `text`, `select-one`, `select-multiple`
|
||||||
|
|
||||||
|
|
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
|
@ -517,7 +517,7 @@ export class Choices {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disable
|
* Disable interaction with Choices
|
||||||
* @return {Object} Class instance
|
* @return {Object} Class instance
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
|
@ -530,6 +530,19 @@ export class Choices {
|
||||||
return this;
|
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
|
* Populate options via ajax callback
|
||||||
* @param {Function} fn Passed
|
* @param {Function} fn Passed
|
||||||
|
|
|
@ -250,6 +250,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
var example12 = new Choices('#choices-15', {
|
var example12 = new Choices('#choices-15', {
|
||||||
|
search: false,
|
||||||
choices: [
|
choices: [
|
||||||
{value: 'One', label: 'Label One'},
|
{value: 'One', label: 'Label One'},
|
||||||
{value: 'Two', label: 'Label Two', disabled: true},
|
{value: 'Two', label: 'Label Two', disabled: true},
|
||||||
|
|
Loading…
Reference in a new issue