2016-03-15 15:39:22 +01:00
<!DOCTYPE html>
< html lang = "en" >
< head >
< meta charset = "UTF-8" >
2016-08-01 21:00:24 +02:00
< meta name = "viewport" content = "width=device-width,initial-scale=1,user-scalable=no" >
2016-03-15 15:39:22 +01:00
< title > Choices< / title >
2016-07-31 23:48:36 +02:00
< meta name = description itemprop = description content = "A lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency." >
2016-07-31 00:26:32 +02:00
<!-- Ignore these -->
2016-08-08 23:00:34 +02:00
< link rel = "stylesheet" href = "assets/styles/css/base.min.css?version=1.1.0" >
2016-07-31 00:26:32 +02:00
< script src = "https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js" > < / script >
<!-- Choices includes -->
2016-08-08 23:00:34 +02:00
< link rel = "stylesheet" href = "assets/styles/css/choices.min.css?version=1.1.0" >
< script src = "assets/scripts/dist/choices.min.js?version=1.1.0" > < / script >
2016-08-04 23:25:35 +02:00
<!-- [if lt IE 9]>
2016-08-05 00:02:34 +02:00
< style >
.hidden-ie { display: none; }
.visible-ie { display: block; }
< / style >
2016-08-04 23:25:35 +02:00
<![endif]-->
2016-03-15 15:39:22 +01:00
< / head >
< body >
2016-04-04 15:43:22 +02:00
< div class = "container" >
2016-04-07 20:44:16 +02:00
< div class = "section" >
2016-08-04 23:25:35 +02:00
< img src = "assets/images/logo.svg" alt = "Choices.js logo" class = "logo hidden-ie" >
< h1 class = "visible-ie" > Choices.js< / h1 >
< p > Choices.js is a lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.< / p >
2016-07-30 17:13:01 +02:00
< p > For all config options, visit the < a href = "https://github.com/jshjohnson/Choices" > GitHub repo< / a > .< / p >
2016-07-31 23:48:36 +02:00
< hr >
2016-05-08 01:02:52 +02:00
< h2 > Text inputs< / h2 >
2016-07-31 21:15:17 +02:00
< label for = "choices-1" > Limited to 5 values< / label >
2016-08-08 22:46:17 +02:00
< input class = "form-control" id = "choices-1" type = "text" value = "preset-1,preset-2" placeholder = "Enter something" >
2016-03-18 12:05:50 +01:00
2016-05-08 13:22:56 +02:00
< label for = "choices-2" > Unique values only, no pasting< / label >
2016-08-08 22:46:17 +02:00
< input class = "form-control" id = "choices-2" type = "text" value = "preset-1, preset-2" placeholder = "This is a placeholder" class = "custom class" >
2016-03-24 15:42:03 +01:00
2016-05-08 01:02:52 +02:00
< label for = "choices-3" > Email addresses only< / label >
2016-08-08 22:46:17 +02:00
< input class = "form-control" id = "choices-3" type = "text" placeholder = "This is a placeholder" >
2016-03-24 15:42:03 +01:00
2016-05-08 01:02:52 +02:00
< label for = "choices-4" > Disabled< / label >
2016-08-08 22:46:17 +02:00
< input class = "form-control" id = "choices-4" type = "text" value = "josh@joshuajohnson.co.uk, joe@bloggs.co.uk" placeholder = "This is a placeholder" >
2016-03-24 15:42:03 +01:00
2016-05-08 01:02:52 +02:00
< label for = "choices-5" > Prepends and appends a value to each items return value< / label >
2016-08-08 22:46:17 +02:00
< input class = "form-control" id = "choices-5" type = "text" value = "preset-1, preset-2" placeholder = "This is a placeholder" >
2016-04-07 14:57:57 +02:00
2016-05-08 01:02:52 +02:00
< label for = "choices-6" > Preset values passed through options< / label >
2016-08-08 22:46:17 +02:00
< input class = "form-control" id = "choices-6" type = "text" value = "olivia@benson.com" placeholder = "This is a placeholder" >
2016-04-08 23:33:13 +02:00
2016-05-12 00:17:22 +02:00
< hr >
2016-05-08 01:02:52 +02:00
< h2 > Multiple select input< / h2 >
< label for = "choices-7" > Default< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" data-choice name = "choices-7" id = "choices-7" placeholder = "This is a placeholder" multiple >
2016-04-10 22:23:42 +02:00
< option value = "Dropdown item 1" > Dropdown item 1< / option >
2016-04-12 23:42:56 +02:00
< option value = "Dropdown item 2" > Dropdown item 2< / option >
2016-05-08 01:02:52 +02:00
< option value = "Dropdown item 3" selected > Dropdown item 3< / option >
2016-05-02 16:29:05 +02:00
< option value = "Dropdown item 4" disabled > Dropdown item 4< / option >
2016-04-10 22:23:42 +02:00
< / select >
2016-06-30 23:08:40 +02:00
< label for = "choices-8" > With pre-selected option< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" data-choice name = "choices-8" id = "choices-8" placeholder = "Choose an option" multiple >
2016-04-08 23:33:13 +02:00
< 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 >
2016-05-03 22:31:05 +02:00
< / select >
2016-06-30 15:11:09 +02:00
2016-06-30 23:08:40 +02:00
< label for = "choices-9" > Option groups< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" data-choice name = "choices-9" id = "choices-9" placeholder = "This is a placeholder" multiple >
2016-04-22 20:45:50 +02:00
< optgroup label = "UK" >
< option value = "London" > London< / option >
< option value = "Manchester" > Manchester< / option >
< option value = "Liverpool" > Liverpool< / option >
2016-04-15 10:19:02 +02:00
< / optgroup >
2016-04-22 20:45:50 +02:00
< optgroup label = "FR" >
< option value = "Paris" > Paris< / option >
< option value = "Lyon" > Lyon< / option >
< option value = "Marseille" > Marseille< / option >
2016-04-15 10:19:02 +02:00
< / optgroup >
2016-05-02 22:39:33 +02:00
< optgroup label = "DE" disabled >
2016-04-22 20:45:50 +02:00
< option value = "Hamburg" > Hamburg< / option >
< option value = "Munich" > Munich< / option >
< option value = "Berlin" > Berlin< / option >
2016-04-15 10:19:02 +02:00
< / optgroup >
2016-05-02 16:29:05 +02:00
< optgroup label = "US" >
< option value = "New York" > New York< / option >
< option value = "Washington" disabled > Washington< / option >
< option value = "Michigan" > Michigan< / option >
< / optgroup >
2016-05-02 22:39:33 +02:00
< 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 >
2016-04-15 10:19:02 +02:00
< / select >
2016-05-08 01:02:52 +02:00
2016-08-14 17:19:09 +02:00
< label for = "choices-10" > Options from remote source (Fetch API) & limited to 5< / label >
< select class = "form-control" name = "choices-10" id = "choices-10" multiple > < / select >
2016-06-30 23:08:40 +02:00
2016-05-12 00:17:22 +02:00
< hr >
2016-05-08 01:02:52 +02:00
< h2 > Single select input< / h2 >
< label for = "choices-11" > Default< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" data-choice name = "choices-11" id = "choices-11" placeholder = "This is a placeholder" >
2016-05-08 01:02:52 +02:00
< 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 >
2016-07-31 21:15:17 +02:00
< label for = "choices-12" > Options from remote source (Fetch API)< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "choices-12" id = "choices-12" placeholder = "Pick an Arctic Monkeys record" > < / select >
2016-05-08 13:27:08 +02:00
2016-08-05 22:17:23 +02:00
< label for = "choices-14" > Options from remote source (XHR)< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "choices-14" id = "choices-14" placeholder = "Pick a Smiths record" > < / select >
2016-08-05 22:17:23 +02:00
2016-05-08 13:27:08 +02:00
< label for = "choices-13" > Option groups< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" data-choice name = "choices-13" id = "choices-13" placeholder = "This is a placeholder" >
2016-05-08 13:27:08 +02:00
< 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 >
2016-06-30 23:25:00 +02:00
2016-08-02 15:40:36 +02:00
< label for = "choices-15" > Options added via config with no search< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "choices-15" id = "choices-15" placeholder = "This is a placeholder" >
2016-07-30 16:12:22 +02:00
< option value = "0" > Zero< / option >
< / select >
2016-07-31 22:05:17 +02:00
2016-08-02 22:02:52 +02:00
< label for = "choices-16" > Option and option groups added via config< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "choices-16" id = "choices-16" placeholder = "This is a placeholder" > < / select >
2016-08-02 22:02:52 +02:00
< label for = "choices-17" > Option selected via config< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "choices-17" id = "choices-17" placeholder = "This is a placeholder" > < / select >
2016-08-04 20:55:55 +02:00
< 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 = "cities" > States< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "cities" id = "cities" placeholder = "Choose a state" >
2016-08-04 20:55:55 +02:00
< option value = "Texas" > Texas< / option >
< option value = "Chicago" > Chicago< / option >
< option value = "New York" > New York< / option >
< option value = "Washington" > Washington< / option >
< option value = "Michigan" > Michigan< / option >
< / select >
< label for = "boroughs" > Boroughs< / label >
2016-08-08 22:46:17 +02:00
< select class = "form-control" name = "boroughs" id = "boroughs" placeholder = "Choose a borough" >
2016-08-04 20:55:55 +02:00
< option value = "The Bronx" > The Bronx< / option >
< option value = "Brooklyn" > Brooklyn< / option >
< option value = "Manhatten" > Manhatten< / option >
< option value = "Queens" > Queens< / option >
< option value = "Staten Island" > Staten Island< / option >
< / select >
2016-04-07 20:44:16 +02:00
< / div >
2016-04-04 15:43:22 +02:00
< / div >
2016-04-25 19:00:30 +02:00
< script >
2016-07-31 00:26:32 +02:00
document.addEventListener('DOMContentLoaded', function() {
2016-08-02 22:02:52 +02:00
var example1 = new Choices(document.getElementById('choices-1'), {
2016-07-30 16:50:29 +02:00
delimiter: ',',
editItems: true,
maxItemCount: 5,
2016-08-04 14:21:24 +02:00
removeItemButton: true,
2016-08-04 15:54:22 +02:00
callbackOnHighlightItem: function(id, value, passedInput) {
console.log(value);
},
callbackOnUnhighlightItem: function(id, value, passedInput) {
console.log(value);
},
2016-07-30 16:50:29 +02:00
});
2016-08-02 22:02:52 +02:00
console.log(example1.getValue());
2016-08-02 08:45:08 +02:00
2016-08-02 22:02:52 +02:00
var example2 = new Choices('#choices-2', {
2016-07-30 16:50:29 +02:00
paste: false,
duplicateItems: false,
editItems: true,
});
2016-08-02 22:02:52 +02:00
var example3 = new Choices('#choices-3', {
2016-07-30 16:50:29 +02:00
duplicates: 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,}))$/,
});
2016-08-02 22:02:52 +02:00
var example4 = new Choices('#choices-4', {
2016-07-30 16:50:29 +02:00
addItems: false,
removeItems: false,
}).disable();
2016-08-02 22:02:52 +02:00
var example5 = new Choices('#choices-5', {
2016-07-30 16:50:29 +02:00
prependValue: 'item-',
2016-08-05 00:02:34 +02:00
appendValue: '-' + Date.now(),
2016-07-30 16:50:29 +02:00
}).removeActiveItems();
2016-08-02 22:02:52 +02:00
var example7 = new Choices('#choices-6', {
2016-07-30 16:50:29 +02:00
items: ['josh@joshuajohnson.co.uk', { value: 'joe@bloggs.co.uk', label: 'Joe Bloggs' } ],
});
2016-07-02 14:04:38 +02:00
2016-08-02 22:02:52 +02:00
var example8 = new Choices('#choices-10', {
2016-07-30 16:50:29 +02:00
placeholder: true,
placeholderValue: 'Pick an Strokes record',
2016-08-14 17:10:53 +02:00
maxItemCount: 5,
2016-07-31 21:02:46 +02:00
callbackOnChange: function(value, passedInput) { console.log(value) }
2016-07-31 00:26:32 +02:00
}).ajax(function(callback) {
2016-07-30 16:50:29 +02:00
fetch('https://api.discogs.com/artists/55980/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
2016-07-31 00:26:32 +02:00
.then(function(response) {
2016-07-30 16:50:29 +02:00
response.json().then(function(data) {
callback(data.releases, 'title', 'title');
});
})
2016-07-31 00:26:32 +02:00
.catch(function(error) {
2016-07-30 16:50:29 +02:00
console.log(error);
});
});
2016-08-02 15:40:36 +02:00
2016-08-02 22:02:52 +02:00
var example9 = new Choices('#choices-12', {
2016-07-30 16:50:29 +02:00
placeholder: true,
placeholderValue: 'Pick an Arctic Monkeys record'
2016-07-31 00:26:32 +02:00
}).ajax(function(callback) {
2016-07-30 16:50:29 +02:00
fetch('https://api.discogs.com/artists/391170/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW')
2016-07-31 00:26:32 +02:00
.then(function(response) {
response.json().then(function(data) {
2016-07-30 16:50:29 +02:00
callback(data.releases, 'title', 'title');
2016-08-07 22:05:43 +02:00
example9.setValueByChoice('Fake Tales Of San Francisco');
2016-07-30 16:50:29 +02:00
});
})
2016-07-31 00:26:32 +02:00
.catch(function(error) {
2016-07-30 16:50:29 +02:00
console.log(error);
});
});
2016-08-07 22:05:43 +02:00
var example10 = new Choices('#choices-14', {
removeItemButton: true,
}).ajax(function(callback) {
2016-07-31 21:15:17 +02:00
var request = new XMLHttpRequest();
2016-08-05 22:17:23 +02:00
request.open('get', 'https://api.discogs.com/artists/83080/releases?token=QBRmstCkwXEvCjTclCpumbtNwvVkEzGAdELXyRyW', true);
2016-07-31 21:15:17 +02:00
request.onreadystatechange = function() {
var status;
var data;
if (request.readyState == 4) {
status = request.status;
if (status == 200) {
data = JSON.parse(request.responseText);
2016-08-05 22:17:23 +02:00
callback(data.releases, 'title', 'title');
example10.setValueByChoice('How Soon Is Now?');
2016-07-31 21:15:17 +02:00
} else {
2016-08-05 21:28:21 +02:00
console.error(status);
2016-07-31 21:15:17 +02:00
}
}
}
request.send();
2016-07-30 16:50:29 +02:00
});
2016-08-02 22:02:52 +02:00
var example11 = new Choices('[data-choice]', {
2016-07-30 16:50:29 +02:00
placeholderValue: 'This is a placeholder set in the config',
2016-08-02 15:40:36 +02:00
removeButton: true,
2016-07-30 16:50:29 +02:00
});
2016-08-02 22:02:52 +02:00
var example12 = new Choices('#choices-15', {
2016-08-02 22:10:53 +02:00
search: false,
2016-07-30 17:03:20 +02:00
choices: [
2016-07-31 22:05:17 +02:00
{value: 'One', label: 'Label One'},
2016-07-30 17:03:20 +02:00
{value: 'Two', label: 'Label Two', disabled: true},
2016-07-30 16:12:22 +02:00
{value: 'Three', label: 'Label Three'},
],
2016-07-31 23:48:36 +02:00
}).setChoices([
2016-07-31 22:05:17 +02:00
{value: 'Four', label: 'Label Four', disabled: true},
2016-07-31 21:02:46 +02:00
{value: 'Five', label: 'Label Five'},
2016-07-31 22:05:17 +02:00
{value: 'Six', label: 'Label Six', selected: true},
2016-07-31 21:02:46 +02:00
], 'value', 'label');
2016-08-02 22:02:52 +02:00
var example13 = new Choices('#choices-16', {
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 example14 = new Choices('#choices-17', {
2016-07-31 22:05:17 +02:00
choices: [
{value: 'One', label: 'Label One'},
{value: 'Two', label: 'Label Two', disabled: true},
{value: 'Three', label: 'Label Three'},
],
2016-07-31 23:48:36 +02:00
}).setValueByChoice('Two');
2016-08-04 20:55:55 +02:00
var cities = new Choices(document.getElementById('cities'), {
callbackOnChange: function(value) {
if(value === 'New York') {
boroughs.enable();
} else {
boroughs.disable();
}
}
});
var boroughs = new Choices(document.getElementById('boroughs')).disable();
2016-04-25 19:00:30 +02:00
});
< / script >
2016-08-02 18:26:08 +02:00
<!-- Google Analytics - Ignore me -->
< script >
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-31575166-1', 'auto');
ga('send', 'pageview');
< / script >
< script async src = 'https://www.google-analytics.com/analytics.js' > < / script >
<!-- End Google Analytics -->
2016-03-15 15:39:22 +01:00
< / body >
< / html >