mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 21:16:34 +02:00
Ability to set item by disabled choice programatically
This commit is contained in:
parent
3d45b1d382
commit
53f7207257
4
assets/scripts/dist/choices.js
vendored
4
assets/scripts/dist/choices.js
vendored
|
@ -1,4 +1,4 @@
|
||||||
/*! choices.js v2.0.4 | (c) 2016 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
|
/*! choices.js v2.0.5 | (c) 2016 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
|
||||||
/******/ (function(modules) { // webpackBootstrap
|
/******/ (function(modules) { // webpackBootstrap
|
||||||
/******/ // The module cache
|
/******/ // The module cache
|
||||||
/******/ var installedModules = {};
|
/******/ var installedModules = {};
|
||||||
|
@ -1915,7 +1915,7 @@
|
||||||
|
|
||||||
this.store.dispatch((0, _index3.addChoice)(value, choiceLabel, choiceId, groupId, isDisabled));
|
this.store.dispatch((0, _index3.addChoice)(value, choiceLabel, choiceId, groupId, isDisabled));
|
||||||
|
|
||||||
if (isSelected && !isDisabled) {
|
if (isSelected) {
|
||||||
this._addItem(value, choiceLabel, choiceId);
|
this._addItem(value, choiceLabel, choiceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
assets/scripts/dist/choices.js.map
vendored
2
assets/scripts/dist/choices.js.map
vendored
File diff suppressed because one or more lines are too long
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
|
@ -1643,7 +1643,7 @@ export default class Choices {
|
||||||
|
|
||||||
this.store.dispatch(addChoice(value, choiceLabel, choiceId, groupId, isDisabled));
|
this.store.dispatch(addChoice(value, choiceLabel, choiceId, groupId, isDisabled));
|
||||||
|
|
||||||
if (isSelected && !isDisabled) {
|
if (isSelected) {
|
||||||
this._addItem(value, choiceLabel, choiceId);
|
this._addItem(value, choiceLabel, choiceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
527
index.html
527
index.html
|
@ -28,11 +28,11 @@
|
||||||
<!-- End Choices includes -->
|
<!-- End Choices includes -->
|
||||||
|
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<style>
|
<style>
|
||||||
.hidden-ie { display: none; }
|
.hidden-ie { display: none; }
|
||||||
.visible-ie { display: block; }
|
.visible-ie { display: block; }
|
||||||
</style>
|
</style>
|
||||||
<![endif]-->
|
<![endif]-->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -71,44 +71,44 @@
|
||||||
<h2>Multiple select input</h2>
|
<h2>Multiple select input</h2>
|
||||||
<label for="choices-multiple-default">Default</label>
|
<label for="choices-multiple-default">Default</label>
|
||||||
<select class="form-control" data-choice name="choices-multiple-default" id="choices-multiple-default" placeholder="This is a placeholder" multiple>
|
<select class="form-control" data-choice name="choices-multiple-default" id="choices-multiple-default" placeholder="This is a placeholder" multiple>
|
||||||
<option value="Dropdown item 1" selected>Dropdown item 1</option>
|
<option value="Dropdown item 1" selected>Dropdown item 1</option>
|
||||||
<option value="Dropdown item 2">Dropdown item 2</option>
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
||||||
<option value="Dropdown item 3">Dropdown item 3</option>
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
||||||
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="choices-multiple-groups">Option groups</label>
|
<label for="choices-multiple-groups">Option groups</label>
|
||||||
<select class="form-control" data-choice name="choices-multiple-groups" id="choices-multiple-groups" placeholder="This is a placeholder" multiple>
|
<select class="form-control" data-choice name="choices-multiple-groups" id="choices-multiple-groups" placeholder="This is a placeholder" multiple>
|
||||||
<optgroup label="UK">
|
<optgroup label="UK">
|
||||||
<option value="London">London</option>
|
<option value="London">London</option>
|
||||||
<option value="Manchester">Manchester</option>
|
<option value="Manchester">Manchester</option>
|
||||||
<option value="Liverpool">Liverpool</option>
|
<option value="Liverpool">Liverpool</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="FR">
|
<optgroup label="FR">
|
||||||
<option value="Paris">Paris</option>
|
<option value="Paris">Paris</option>
|
||||||
<option value="Lyon">Lyon</option>
|
<option value="Lyon">Lyon</option>
|
||||||
<option value="Marseille">Marseille</option>
|
<option value="Marseille">Marseille</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="DE" disabled>
|
<optgroup label="DE" disabled>
|
||||||
<option value="Hamburg">Hamburg</option>
|
<option value="Hamburg">Hamburg</option>
|
||||||
<option value="Munich">Munich</option>
|
<option value="Munich">Munich</option>
|
||||||
<option value="Berlin">Berlin</option>
|
<option value="Berlin">Berlin</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="US">
|
<optgroup label="US">
|
||||||
<option value="New York">New York</option>
|
<option value="New York">New York</option>
|
||||||
<option value="Washington" disabled>Washington</option>
|
<option value="Washington" disabled>Washington</option>
|
||||||
<option value="Michigan">Michigan</option>
|
<option value="Michigan">Michigan</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="SP">
|
<optgroup label="SP">
|
||||||
<option value="Madrid">Madrid</option>
|
<option value="Madrid">Madrid</option>
|
||||||
<option value="Barcelona">Barcelona</option>
|
<option value="Barcelona">Barcelona</option>
|
||||||
<option value="Malaga">Malaga</option>
|
<option value="Malaga">Malaga</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="CA">
|
<optgroup label="CA">
|
||||||
<option value="Montreal">Montreal</option>
|
<option value="Montreal">Montreal</option>
|
||||||
<option value="Toronto">Toronto</option>
|
<option value="Toronto">Toronto</option>
|
||||||
<option value="Vancouver">Vancouver</option>
|
<option value="Vancouver">Vancouver</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="choices-multiple-remote-fetch">Options from remote source (Fetch API) & limited to 5</label>
|
<label for="choices-multiple-remote-fetch">Options from remote source (Fetch API) & limited to 5</label>
|
||||||
|
@ -116,20 +116,21 @@
|
||||||
|
|
||||||
<label for="choices-multiple-rtl">Right-to-left</label>
|
<label for="choices-multiple-rtl">Right-to-left</label>
|
||||||
<select class="form-control" data-choice name="choices-multiple-rtl" id="choices-multiple-rtl" placeholder="This is a placeholder" multiple dir="rtl">
|
<select class="form-control" data-choice name="choices-multiple-rtl" id="choices-multiple-rtl" placeholder="This is a placeholder" multiple dir="rtl">
|
||||||
<option value="Dropdown item 1" selected>Dropdown item 1</option>
|
<option value="Dropdown item 1" selected>Dropdown item 1</option>
|
||||||
<option value="Dropdown item 2">Dropdown item 2</option>
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
||||||
<option value="Dropdown item 3">Dropdown item 3</option>
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
||||||
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h2>Single select input</h2>
|
<h2>Single select input</h2>
|
||||||
<label for="choices-single-default">Default</label>
|
<label for="choices-single-default">Default</label>
|
||||||
<select class="form-control" data-choice name="choices-single-default" id="choices-single-default" placeholder="This is a placeholder">
|
<select class="form-control" data-choice name="choices-single-default" id="choices-single-default" placeholder="This is a search placeholder">
|
||||||
<option value="Dropdown item 1">Dropdown item 1</option>
|
<option selected disabled>This is a placeholder</option>
|
||||||
<option value="Dropdown item 2">Dropdown item 2</option>
|
<option value="Dropdown item 1">Dropdown item 1</option>
|
||||||
<option value="Dropdown item 3">Dropdown item 3</option>
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
||||||
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="choices-single-remote-fetch">Options from remote source (Fetch API)</label>
|
<label for="choices-single-remote-fetch">Options from remote source (Fetch API)</label>
|
||||||
|
@ -140,48 +141,48 @@
|
||||||
|
|
||||||
<label for="choices-single-groups">Option groups</label>
|
<label for="choices-single-groups">Option groups</label>
|
||||||
<select class="form-control" data-choice name="choices-single-groups" id="choices-single-groups" placeholder="This is a placeholder">
|
<select class="form-control" data-choice name="choices-single-groups" id="choices-single-groups" placeholder="This is a placeholder">
|
||||||
<optgroup label="UK">
|
<optgroup label="UK">
|
||||||
<option value="London">London</option>
|
<option value="London">London</option>
|
||||||
<option value="Manchester">Manchester</option>
|
<option value="Manchester">Manchester</option>
|
||||||
<option value="Liverpool">Liverpool</option>
|
<option value="Liverpool">Liverpool</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="FR">
|
<optgroup label="FR">
|
||||||
<option value="Paris">Paris</option>
|
<option value="Paris">Paris</option>
|
||||||
<option value="Lyon">Lyon</option>
|
<option value="Lyon">Lyon</option>
|
||||||
<option value="Marseille">Marseille</option>
|
<option value="Marseille">Marseille</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="DE" disabled>
|
<optgroup label="DE" disabled>
|
||||||
<option value="Hamburg">Hamburg</option>
|
<option value="Hamburg">Hamburg</option>
|
||||||
<option value="Munich">Munich</option>
|
<option value="Munich">Munich</option>
|
||||||
<option value="Berlin">Berlin</option>
|
<option value="Berlin">Berlin</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="US">
|
<optgroup label="US">
|
||||||
<option value="New York">New York</option>
|
<option value="New York">New York</option>
|
||||||
<option value="Washington" disabled>Washington</option>
|
<option value="Washington" disabled>Washington</option>
|
||||||
<option value="Michigan">Michigan</option>
|
<option value="Michigan">Michigan</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="SP">
|
<optgroup label="SP">
|
||||||
<option value="Madrid">Madrid</option>
|
<option value="Madrid">Madrid</option>
|
||||||
<option value="Barcelona">Barcelona</option>
|
<option value="Barcelona">Barcelona</option>
|
||||||
<option value="Malaga">Malaga</option>
|
<option value="Malaga">Malaga</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
<optgroup label="CA">
|
<optgroup label="CA">
|
||||||
<option value="Montreal">Montreal</option>
|
<option value="Montreal">Montreal</option>
|
||||||
<option value="Toronto">Toronto</option>
|
<option value="Toronto">Toronto</option>
|
||||||
<option value="Vancouver">Vancouver</option>
|
<option value="Vancouver">Vancouver</option>
|
||||||
</optgroup>
|
</optgroup>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="choices-single-rtl">Right-to-left</label>
|
<label for="choices-single-rtl">Right-to-left</label>
|
||||||
<select class="form-control" data-choice name="choices-single-rtl" id="choices-single-rtl" placeholder="This is a placeholder" dir="rtl">
|
<select class="form-control" data-choice name="choices-single-rtl" id="choices-single-rtl" placeholder="This is a placeholder" dir="rtl">
|
||||||
<option value="Dropdown item 1">Dropdown item 1</option>
|
<option value="Dropdown item 1">Dropdown item 1</option>
|
||||||
<option value="Dropdown item 2">Dropdown item 2</option>
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
||||||
<option value="Dropdown item 3">Dropdown item 3</option>
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="choices-single-no-search">Options added via config with no search</label>
|
<label for="choices-single-no-search">Options added via config with no search</label>
|
||||||
<select class="form-control" name="choices-single-no-search" id="choices-single-no-search">
|
<select class="form-control" name="choices-single-no-search" id="choices-single-no-search">
|
||||||
<option value="0">Zero</option>
|
<option value="0">Zero</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="choices-single-preset-options">Option and option groups added via config</label>
|
<label for="choices-single-preset-options">Option and option groups added via config</label>
|
||||||
|
@ -192,214 +193,214 @@
|
||||||
|
|
||||||
<label for="choices-single-no-sorting">Options without sorting</label>
|
<label for="choices-single-no-sorting">Options without sorting</label>
|
||||||
<select class="form-control" name="choices-single-no-sorting" id="choices-single-no-sorting" placeholder="This is a placeholder">
|
<select class="form-control" name="choices-single-no-sorting" id="choices-single-no-sorting" placeholder="This is a placeholder">
|
||||||
<option value="Madrid">Madrid</option>
|
<option value="Madrid">Madrid</option>
|
||||||
<option value="Toronto">Toronto</option>
|
<option value="Toronto">Toronto</option>
|
||||||
<option value="Vancouver">Vancouver</option>
|
<option value="Vancouver">Vancouver</option>
|
||||||
<option value="London">London</option>
|
<option value="London">London</option>
|
||||||
<option value="Manchester">Manchester</option>
|
<option value="Manchester">Manchester</option>
|
||||||
<option value="Liverpool">Liverpool</option>
|
<option value="Liverpool">Liverpool</option>
|
||||||
<option value="Paris">Paris</option>
|
<option value="Paris">Paris</option>
|
||||||
<option value="Malaga">Malaga</option>
|
<option value="Malaga">Malaga</option>
|
||||||
<option value="Washington" disabled>Washington</option>
|
<option value="Washington" disabled>Washington</option>
|
||||||
<option value="Lyon">Lyon</option>
|
<option value="Lyon">Lyon</option>
|
||||||
<option value="Marseille">Marseille</option>
|
<option value="Marseille">Marseille</option>
|
||||||
<option value="Hamburg">Hamburg</option>
|
<option value="Hamburg">Hamburg</option>
|
||||||
<option value="Munich">Munich</option>
|
<option value="Munich">Munich</option>
|
||||||
<option value="Barcelona">Barcelona</option>
|
<option value="Barcelona">Barcelona</option>
|
||||||
<option value="Berlin">Berlin</option>
|
<option value="Berlin">Berlin</option>
|
||||||
<option value="Montreal">Montreal</option>
|
<option value="Montreal">Montreal</option>
|
||||||
<option value="New York">New York</option>
|
<option value="New York">New York</option>
|
||||||
<option value="Michigan">Michigan</option>
|
<option value="Michigan">Michigan</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<p>Below is an example of how you could have two select inputs depend on eachother. 'Boroughs' will only be enabled if the value of 'States' is 'New York'</p>
|
<p>Below is an example of how you could have two select inputs depend on eachother. 'Boroughs' will only be enabled if the value of 'States' is 'New York'</p>
|
||||||
<label for="states">States</label>
|
<label for="states">States</label>
|
||||||
<select class="form-control" name="states" id="states" placeholder="Choose a state">
|
<select class="form-control" name="states" id="states" placeholder="Choose a state">
|
||||||
<option value="Michigan">Michigan</option>
|
<option value="Michigan">Michigan</option>
|
||||||
<option value="Texas">Texas</option>
|
<option value="Texas">Texas</option>
|
||||||
<option value="Chicago">Chicago</option>
|
<option value="Chicago">Chicago</option>
|
||||||
<option value="New York">New York</option>
|
<option value="New York">New York</option>
|
||||||
<option value="Washington">Washington</option>
|
<option value="Washington">Washington</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<label for="boroughs">Boroughs</label>
|
<label for="boroughs">Boroughs</label>
|
||||||
<select class="form-control" name="boroughs" id="boroughs" placeholder="Choose a borough">
|
<select class="form-control" name="boroughs" id="boroughs" placeholder="Choose a borough">
|
||||||
<option value="The Bronx">The Bronx</option>
|
<option value="The Bronx">The Bronx</option>
|
||||||
<option value="Brooklyn">Brooklyn</option>
|
<option value="Brooklyn">Brooklyn</option>
|
||||||
<option value="Manhattan">Manhattan</option>
|
<option value="Manhattan">Manhattan</option>
|
||||||
<option value="Queens">Queens</option>
|
<option value="Queens">Queens</option>
|
||||||
<option value="Staten Island">Staten Island</option>
|
<option value="Staten Island">Staten Island</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var example1 = new Choices(document.getElementById('choices-text-remove-button'), {
|
var example1 = new Choices(document.getElementById('choices-text-remove-button'), {
|
||||||
delimiter: ',',
|
delimiter: ',',
|
||||||
editItems: true,
|
editItems: true,
|
||||||
maxItemCount: 5,
|
maxItemCount: 5,
|
||||||
removeItemButton: true,
|
removeItemButton: true,
|
||||||
callbackOnHighlightItem: function(id, value, passedInput) {
|
callbackOnHighlightItem: function(id, value, passedInput) {
|
||||||
console.log(value);
|
console.log(value);
|
||||||
},
|
|
||||||
callbackOnUnhighlightItem: function(id, value, passedInput) {
|
|
||||||
console.log(value);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
var example2 = new Choices('#choices-text-unique-values', {
|
|
||||||
paste: false,
|
|
||||||
duplicateItems: false,
|
|
||||||
editItems: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
var example3 = new Choices('#choices-text-email-filter', {
|
|
||||||
editItems: true,
|
|
||||||
regexFilter: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
|
||||||
});
|
|
||||||
|
|
||||||
var example4 = new Choices('#choices-text-disabled', {
|
|
||||||
addItems: false,
|
|
||||||
removeItems: false,
|
|
||||||
}).disable();
|
|
||||||
|
|
||||||
var example5 = new Choices('#choices-text-prepend-append-value', {
|
|
||||||
prependValue: 'item-',
|
|
||||||
appendValue: '-' + Date.now(),
|
|
||||||
}).removeActiveItems();
|
|
||||||
|
|
||||||
var example7 = new Choices('#choices-text-preset-values', {
|
|
||||||
items: ['josh@joshuajohnson.co.uk', { value: 'joe@bloggs.co.uk', label: 'Joe Bloggs' } ],
|
|
||||||
});
|
|
||||||
|
|
||||||
var example9 = new Choices('#choices-multiple-remote-fetch', {
|
|
||||||
placeholder: true,
|
|
||||||
placeholderValue: 'Pick an Strokes record',
|
|
||||||
maxItemCount: 5,
|
|
||||||
callbackOnChange: function(value, passedInput) { console.log(value) }
|
|
||||||
}).ajax(function(callback) {
|
|
||||||
fetch('https://api.discogs.com/artists/55980/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
|
|
||||||
.then(function(response) {
|
|
||||||
response.json().then(function(data) {
|
|
||||||
callback(data.releases, 'title', 'title');
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var example10 = new Choices('#choices-single-remote-fetch', {
|
|
||||||
placeholder: true,
|
|
||||||
placeholderValue: 'Pick an Arctic Monkeys record'
|
|
||||||
}).ajax(function(callback) {
|
|
||||||
fetch('https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
|
|
||||||
.then(function(response) {
|
|
||||||
response.json().then(function(data) {
|
|
||||||
callback(data.releases, 'title', 'title');
|
|
||||||
example10.setValueByChoice('Fake Tales Of San Francisco');
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(function(error) {
|
|
||||||
console.log(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
var example11 = new Choices('#choices-single-remove-xhr', {
|
|
||||||
removeItemButton: true,
|
|
||||||
}).ajax(function(callback) {
|
|
||||||
var request = new XMLHttpRequest();
|
|
||||||
request.open('get', 'https://api.discogs.com/artists/83080/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW', true);
|
|
||||||
request.onreadystatechange = function() {
|
|
||||||
var status;
|
|
||||||
var data;
|
|
||||||
if (request.readyState === 4) {
|
|
||||||
status = request.status;
|
|
||||||
if (status === 200) {
|
|
||||||
data = JSON.parse(request.responseText);
|
|
||||||
callback(data.releases, 'title', 'title');
|
|
||||||
example11.setValueByChoice('How Soon Is Now?');
|
|
||||||
} else {
|
|
||||||
console.error(status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request.send();
|
|
||||||
});
|
|
||||||
|
|
||||||
var example12 = new Choices('[data-choice]', {
|
|
||||||
placeholderValue: 'This is a placeholder set in the config',
|
|
||||||
removeButton: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
var example13 = new Choices('#choices-single-no-search', {
|
|
||||||
search: false,
|
|
||||||
removeItemButton: true,
|
|
||||||
choices: [
|
|
||||||
{value: 'One', label: 'Label One'},
|
|
||||||
{value: 'Two', label: 'Label Two', disabled: true},
|
|
||||||
{value: 'Three', label: 'Label Three'},
|
|
||||||
],
|
|
||||||
}).setChoices([
|
|
||||||
{value: 'Four', label: 'Label Four', disabled: true},
|
|
||||||
{value: 'Five', label: 'Label Five'},
|
|
||||||
{value: 'Six', label: 'Label Six', selected: true},
|
|
||||||
], 'value', 'label');
|
|
||||||
|
|
||||||
var example14 = new Choices('#choices-single-preset-options', {
|
|
||||||
placeholder: true,
|
|
||||||
}).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'},
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
callbackOnUnhighlightItem: function(id, value, passedInput) {
|
||||||
label: 'Group two',
|
console.log(value);
|
||||||
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');
|
|
||||||
|
|
||||||
var example15 = new Choices('#choices-single-selected-option', {
|
var example2 = new Choices('#choices-text-unique-values', {
|
||||||
choices: [
|
paste: false,
|
||||||
{value: 'One', label: 'Label One', selected: true},
|
duplicateItems: false,
|
||||||
{value: 'Two', label: 'Label Two', disabled: true},
|
editItems: true,
|
||||||
{value: 'Three', label: 'Label Three'},
|
});
|
||||||
],
|
|
||||||
}).setValueByChoice('Two');
|
|
||||||
|
|
||||||
var example16 = new Choices('#choices-single-no-sorting', {
|
var example3 = new Choices('#choices-text-email-filter', {
|
||||||
shouldSort: false,
|
editItems: true,
|
||||||
|
regexFilter: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
|
||||||
|
});
|
||||||
|
|
||||||
|
var example4 = new Choices('#choices-text-disabled', {
|
||||||
|
addItems: false,
|
||||||
|
removeItems: false,
|
||||||
|
}).disable();
|
||||||
|
|
||||||
|
var example5 = new Choices('#choices-text-prepend-append-value', {
|
||||||
|
prependValue: 'item-',
|
||||||
|
appendValue: '-' + Date.now(),
|
||||||
|
}).removeActiveItems();
|
||||||
|
|
||||||
|
var example7 = new Choices('#choices-text-preset-values', {
|
||||||
|
items: ['josh@joshuajohnson.co.uk', { value: 'joe@bloggs.co.uk', label: 'Joe Bloggs' } ],
|
||||||
|
});
|
||||||
|
|
||||||
|
var example9 = new Choices('#choices-multiple-remote-fetch', {
|
||||||
|
placeholder: true,
|
||||||
|
placeholderValue: 'Pick an Strokes record',
|
||||||
|
maxItemCount: 5,
|
||||||
|
callbackOnChange: function(value, passedInput) { console.log(value) }
|
||||||
|
}).ajax(function(callback) {
|
||||||
|
fetch('https://api.discogs.com/artists/55980/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
|
||||||
|
.then(function(response) {
|
||||||
|
response.json().then(function(data) {
|
||||||
|
callback(data.releases, 'title', 'title');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var states = new Choices(document.getElementById('states'), {
|
var example10 = new Choices('#choices-single-remote-fetch', {
|
||||||
callbackOnChange: function(value) {
|
placeholder: true,
|
||||||
if(value === 'New York') {
|
placeholderValue: 'Pick an Arctic Monkeys record'
|
||||||
boroughs.enable();
|
}).ajax(function(callback) {
|
||||||
} else {
|
fetch('https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
|
||||||
boroughs.disable();
|
.then(function(response) {
|
||||||
}
|
response.json().then(function(data) {
|
||||||
|
callback(data.releases, 'title', 'title');
|
||||||
|
example10.setValueByChoice('Fake Tales Of San Francisco');
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(function(error) {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var example11 = new Choices('#choices-single-remove-xhr', {
|
||||||
|
removeItemButton: true,
|
||||||
|
}).ajax(function(callback) {
|
||||||
|
var request = new XMLHttpRequest();
|
||||||
|
request.open('get', 'https://api.discogs.com/artists/83080/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW', true);
|
||||||
|
request.onreadystatechange = function() {
|
||||||
|
var status;
|
||||||
|
var data;
|
||||||
|
if (request.readyState === 4) {
|
||||||
|
status = request.status;
|
||||||
|
if (status === 200) {
|
||||||
|
data = JSON.parse(request.responseText);
|
||||||
|
callback(data.releases, 'title', 'title');
|
||||||
|
example11.setValueByChoice('How Soon Is Now?');
|
||||||
|
} else {
|
||||||
|
console.error(status);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
request.send();
|
||||||
|
});
|
||||||
|
|
||||||
var boroughs = new Choices(document.getElementById('boroughs')).disable();
|
var example12 = new Choices('[data-choice]', {
|
||||||
|
placeholderValue: 'This is a placeholder set in the config',
|
||||||
|
removeButton: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
var example13 = new Choices('#choices-single-no-search', {
|
||||||
|
search: false,
|
||||||
|
removeItemButton: true,
|
||||||
|
choices: [
|
||||||
|
{value: 'One', label: 'Label One'},
|
||||||
|
{value: 'Two', label: 'Label Two', disabled: true},
|
||||||
|
{value: 'Three', label: 'Label Three'},
|
||||||
|
],
|
||||||
|
}).setChoices([
|
||||||
|
{value: 'Four', label: 'Label Four', disabled: true},
|
||||||
|
{value: 'Five', label: 'Label Five'},
|
||||||
|
{value: 'Six', label: 'Label Six', selected: true},
|
||||||
|
], 'value', 'label');
|
||||||
|
|
||||||
|
var example14 = new Choices('#choices-single-preset-options', {
|
||||||
|
placeholder: true,
|
||||||
|
}).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');
|
||||||
|
|
||||||
|
var example15 = new Choices('#choices-single-selected-option', {
|
||||||
|
choices: [
|
||||||
|
{value: 'One', label: 'Label One', selected: true},
|
||||||
|
{value: 'Two', label: 'Label Two', disabled: true},
|
||||||
|
{value: 'Three', label: 'Label Three'},
|
||||||
|
],
|
||||||
|
}).setValueByChoice('Two');
|
||||||
|
|
||||||
|
var example16 = new Choices('#choices-single-no-sorting', {
|
||||||
|
shouldSort: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
var states = new Choices(document.getElementById('states'), {
|
||||||
|
callbackOnChange: function(value) {
|
||||||
|
if(value === 'New York') {
|
||||||
|
boroughs.enable();
|
||||||
|
} else {
|
||||||
|
boroughs.disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var boroughs = new Choices(document.getElementById('boroughs')).disable();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Google Analytics - Ignore me -->
|
<!-- Google Analytics - Ignore me -->
|
||||||
<script>
|
<script>
|
||||||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
||||||
ga('create', 'UA-31575166-1', 'auto');
|
ga('create', 'UA-31575166-1', 'auto');
|
||||||
ga('send', 'pageview');
|
ga('send', 'pageview');
|
||||||
</script>
|
</script>
|
||||||
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
||||||
<!-- End Google Analytics -->
|
<!-- End Google Analytics -->
|
||||||
|
|
Loading…
Reference in a new issue