mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-17 21:16:34 +02:00
167 lines
7.7 KiB
HTML
167 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>Choices</title>
|
|
<link rel="stylesheet" href="assets/styles/css/choices.css">
|
|
<script src="assets/scripts/dist/choices.js"></script>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="section">
|
|
<h1>Choices</h1>
|
|
<label for="choices-1">Text input with no values and a limit of 5 items</label>
|
|
<input id="choices-1" type="text" value="preset-1 preset-2">
|
|
|
|
<label for="choices-2">Text input with preset values, custom classes and a placeholder. No duplicate values allowed</label>
|
|
<input id="choices-2" type="text" value="preset-1, preset-2" placeholder="This is a placeholder" class="custom class">
|
|
|
|
<label for="choices-3">Text input that only allows email addresses</label>
|
|
<input id="choices-3" type="text" placeholder="This is a placeholder">
|
|
|
|
<label for="choices-4">Text input that disables adding items</label>
|
|
<input id="choices-4" type="text" value="josh@joshuajohnson.co.uk, joe@bloggs.co.uk" placeholder="This is a placeholder">
|
|
|
|
<label for="choices-5">Text input that prepends and appends a value to each items return value</label>
|
|
<input id="choices-5" type="text" value="preset-1, preset-2" placeholder="This is a placeholder">
|
|
|
|
<label for="choices-6">Text input with preset values passed through options</label>
|
|
<input id="choices-6" type="text" placeholder="This is a placeholder">
|
|
|
|
<label for="choices-11">Single select box</label>
|
|
<select id="choices-11" name="choices-11" data-choice placeholder="This is a placeholder">
|
|
<option value="Dropdown item 1">Dropdown item 1</option>
|
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
|
</select>
|
|
|
|
<label for="choices-7">Select box</label>
|
|
<select name="choices-7" id="choices-7" placeholder="This is a placeholder" multiple>
|
|
<option value="Dropdown item 1">Dropdown item 1</option>
|
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
|
<option value="Dropdown item 3" selected disabled>Dropdown item 3</option>
|
|
<option value="Dropdown item 4" disabled>Dropdown item 4</option>
|
|
</select>
|
|
|
|
<label for="choices-8">Select box</label>
|
|
<select id="choices-8" name="choices-8" data-choice placeholder="This is a placeholder" multiple>
|
|
<option value="Dropdown item 1">Dropdown item 1</option>
|
|
<option value="Dropdown item 2">Dropdown item 2</option>
|
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
|
</select>
|
|
|
|
<label for="choices-9">Select box with pre-selected option</label>
|
|
<select id="choices-9" name="choices-9" data-choice placeholder="Choose an option" multiple>
|
|
<option value="Dropdown item 1">Dropdown item 1</option>
|
|
<option value="Dropdown item 2" selected>Dropdown item 2</option>
|
|
<option value="Dropdown item 3">Dropdown item 3</option>
|
|
</select>
|
|
|
|
<label for="choices-10">Select box with option groups</label>
|
|
<select id="choices-10" name="choices-10" data-choice placeholder="This is a placeholder" multiple>
|
|
<optgroup label="UK">
|
|
<option value="London">London</option>
|
|
<option value="Manchester">Manchester</option>
|
|
<option value="Liverpool">Liverpool</option>
|
|
</optgroup>
|
|
<optgroup label="FR">
|
|
<option value="Paris">Paris</option>
|
|
<option value="Lyon">Lyon</option>
|
|
<option value="Marseille">Marseille</option>
|
|
</optgroup>
|
|
<optgroup label="DE" disabled>
|
|
<option value="Hamburg">Hamburg</option>
|
|
<option value="Munich">Munich</option>
|
|
<option value="Berlin">Berlin</option>
|
|
</optgroup>
|
|
<optgroup label="US">
|
|
<option value="New York">New York</option>
|
|
<option value="Washington" disabled>Washington</option>
|
|
<option value="Michigan">Michigan</option>
|
|
</optgroup>
|
|
<optgroup label="SP">
|
|
<option value="Madrid">Madrid</option>
|
|
<option value="Barcelona">Barcelona</option>
|
|
<option value="Malaga">Malaga</option>
|
|
</optgroup>
|
|
<optgroup label="CA">
|
|
<option value="Montreal">Montreal</option>
|
|
<option value="Toronto">Toronto</option>
|
|
<option value="Vancouver">Vancouver</option>
|
|
</optgroup>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const firstElement = document.getElementById('choices-1');
|
|
const choices1 = new Choices(firstElement, {
|
|
delimiter: ' ',
|
|
editItems: true,
|
|
maxItems: 5,
|
|
// callbackOnRemoveItem: function(value) {
|
|
// console.log(value);
|
|
// },
|
|
// callbackOnAddItem: function(id, value) {
|
|
// console.log(id, value);
|
|
// },
|
|
// callbackOnRender: function(items) {
|
|
// console.log(items);
|
|
// }
|
|
});
|
|
|
|
const choices2 = new Choices('#choices-2', {
|
|
allowPaste: false,
|
|
allowDuplicates: false,
|
|
editItems: true,
|
|
});
|
|
|
|
const choices3 = new Choices('#choices-3', {
|
|
allowDuplicates: 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,}))$/,
|
|
});
|
|
|
|
const choices4 = new Choices('#choices-4', {
|
|
addItems: false,
|
|
removeItems: false,
|
|
});
|
|
|
|
const choices5 = new Choices('#choices-5', {
|
|
prependValue: 'item-',
|
|
appendValue: `-${Date.now()}`,
|
|
// callbackOnRender: function(items, options) {
|
|
// console.log(items);
|
|
// },
|
|
});
|
|
|
|
choices5.removeActiveItems();
|
|
|
|
const choices6 = new Choices('#choices-6', {
|
|
items: ['josh@joshuajohnson.co.uk', 'joe@bloggs.co.uk'],
|
|
// callbackOnRender: function(items, options, groups) {
|
|
// console.log(items);
|
|
// },
|
|
});
|
|
|
|
const choices7 = new Choices('#choices-7', {
|
|
// callbackOnRender: function(items, options) {
|
|
// console.log(items);
|
|
// },
|
|
});
|
|
|
|
const choicesMultiple = new Choices('[data-choice]', {
|
|
placeholderValue: 'This is a placeholder set in the config',
|
|
// callbackOnRender: function(items, options, groups) {
|
|
// console.log(options);
|
|
// },
|
|
});
|
|
|
|
// choices6.addItem('josh2@joshuajohnson.co.uk', null, null, () => { console.log('Custom add item callback')});
|
|
// choices6.removeItemsByValue('josh@joshuajohnson.co.uk');
|
|
// console.log(choices6.getItemById(3));
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |