mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-19 14:06:33 +02:00
Deep merge of user config
This commit is contained in:
parent
efd70a72ea
commit
c8f12bc942
|
@ -164,7 +164,8 @@ default class Choices {
|
||||||
if (!cuttingTheMustard) console.error('Choices: Your browser doesn\'t support Choices');
|
if (!cuttingTheMustard) console.error('Choices: Your browser doesn\'t support Choices');
|
||||||
|
|
||||||
// Input type check
|
// Input type check
|
||||||
const canInit = this.passedElement && isElement(this.passedElement) && ['select-one', 'select-multiple', 'text'].some(type => type === this.passedElement.type);
|
const canInit = this.passedElement && isElement(this.passedElement) && ['select-one', 'select-multiple', 'text'].some(type => type === this.passedElement
|
||||||
|
.type);
|
||||||
|
|
||||||
if (canInit) {
|
if (canInit) {
|
||||||
// If element has already been initalised with Choices
|
// If element has already been initalised with Choices
|
||||||
|
@ -657,7 +658,8 @@ default class Choices {
|
||||||
// Remove loading states/text
|
// Remove loading states/text
|
||||||
this.containerOuter.classList.remove(this.config.classNames.loadingState);
|
this.containerOuter.classList.remove(this.config.classNames.loadingState);
|
||||||
if (this.passedElement.type === 'select-multiple') {
|
if (this.passedElement.type === 'select-multiple') {
|
||||||
const placeholder = this.config.placeholder ? this.config.placeholderValue || this.passedElement.getAttribute('placeholder') : false;
|
const placeholder = this.config.placeholder ? this.config.placeholderValue || this.passedElement.getAttribute('placeholder') :
|
||||||
|
false;
|
||||||
if (placeholder) {
|
if (placeholder) {
|
||||||
this.input.placeholder = placeholder;
|
this.input.placeholder = placeholder;
|
||||||
}
|
}
|
||||||
|
@ -1697,9 +1699,11 @@ default class Choices {
|
||||||
const classNames = this.config.classNames;
|
const classNames = this.config.classNames;
|
||||||
const templates = {
|
const templates = {
|
||||||
containerOuter: (direction) => {
|
containerOuter: (direction) => {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.containerOuter}" data-type="${this.passedElement.type}" ${this.passedElement.type === 'select-one' ? 'tabindex="0"' : ''} aria-haspopup="true" aria-expanded="false" dir="${direction}"></div>
|
<div class="${classNames.containerOuter}" data-type="${this.passedElement.type}" ${this.passedElement.type === 'select-one' ? 'tabindex="0"' : ''} aria-haspopup="true" aria-expanded="false" dir="${direction}"></div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
containerInner: () => {
|
containerInner: () => {
|
||||||
return strToEl(`
|
return strToEl(`
|
||||||
|
@ -1707,9 +1711,11 @@ default class Choices {
|
||||||
`);
|
`);
|
||||||
},
|
},
|
||||||
itemList: () => {
|
itemList: () => {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.list} ${this.passedElement.type === 'select-one' ? classNames.listSingle : classNames.listItems}"></div>
|
<div class="${classNames.list} ${this.passedElement.type === 'select-one' ? classNames.listSingle : classNames.listItems}"></div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
placeholder: (value) => {
|
placeholder: (value) => {
|
||||||
return strToEl(`
|
return strToEl(`
|
||||||
|
@ -1718,41 +1724,53 @@ default class Choices {
|
||||||
},
|
},
|
||||||
item: (data) => {
|
item: (data) => {
|
||||||
if (this.config.removeItemButton) {
|
if (this.config.removeItemButton) {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.item} ${data.highlighted ? classNames.highlightedState : ''} ${!data.disabled ? classNames.itemSelectable : ''}" data-item data-id="${data.id}" data-value="${data.value}" ${data.active ? 'aria-selected="true"' : ''} ${data.disabled ? 'aria-disabled="true"' : ''} data-deletable>
|
<div class="${classNames.item} ${data.highlighted ? classNames.highlightedState : ''} ${!data.disabled ? classNames.itemSelectable : ''}" data-item data-id="${data.id}" data-value="${data.value}" ${data.active ? 'aria-selected="true"' : ''} ${data.disabled ? 'aria-disabled="true"' : ''} data-deletable>
|
||||||
${data.label}<button class="${classNames.button}" data-button>Remove item</button>
|
${data.label}<button class="${classNames.button}" data-button>Remove item</button>
|
||||||
</div>
|
</div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.item} ${data.highlighted ? classNames.highlightedState : classNames.itemSelectable}" data-item data-id="${data.id}" data-value="${data.value}" ${data.active ? 'aria-selected="true"' : ''} ${data.disabled ? 'aria-disabled="true"' : ''}>
|
<div class="${classNames.item} ${data.highlighted ? classNames.highlightedState : classNames.itemSelectable}" data-item data-id="${data.id}" data-value="${data.value}" ${data.active ? 'aria-selected="true"' : ''} ${data.disabled ? 'aria-disabled="true"' : ''}>
|
||||||
${data.label}
|
${data.label}
|
||||||
</div>
|
</div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
choiceList: () => {
|
choiceList: () => {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.list}" dir="ltr" role="listbox" ${this.passedElement.type !== 'select-one' ? 'aria-multiselectable="true"' : ''}></div>
|
<div class="${classNames.list}" dir="ltr" role="listbox" ${this.passedElement.type !== 'select-one' ? 'aria-multiselectable="true"' : ''}></div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
choiceGroup: (data) => {
|
choiceGroup: (data) => {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.group} ${data.disabled ? classNames.itemDisabled : ''}" data-group data-id="${data.id}" data-value="${data.value}" role="group" ${data.disabled ? 'aria-disabled="true"' : ''}>
|
<div class="${classNames.group} ${data.disabled ? classNames.itemDisabled : ''}" data-group data-id="${data.id}" data-value="${data.value}" role="group" ${data.disabled ? 'aria-disabled="true"' : ''}>
|
||||||
<div class="${classNames.groupHeading}">${data.value}</div>
|
<div class="${classNames.groupHeading}">${data.value}</div>
|
||||||
</div>
|
</div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
choice: (data) => {
|
choice: (data) => {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<div class="${classNames.item} ${classNames.itemChoice} ${data.disabled ? classNames.itemDisabled : classNames.itemSelectable}" data-choice ${data.disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable'} data-id="${data.id}" data-value="${data.value}" ${data.groupId > 0 ? 'role="treeitem"' : 'role="option"'}>
|
<div class="${classNames.item} ${classNames.itemChoice} ${data.disabled ? classNames.itemDisabled : classNames.itemSelectable}" data-choice ${data.disabled ? 'data-choice-disabled aria-disabled="true"' : 'data-choice-selectable'} data-id="${data.id}" data-value="${data.value}" ${data.groupId > 0 ? 'role="treeitem"' : 'role="option"'}>
|
||||||
${data.label}
|
${data.label}
|
||||||
</div>
|
</div>
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
input: () => {
|
input: () => {
|
||||||
return strToEl(`
|
return strToEl(
|
||||||
|
`
|
||||||
<input type="text" class="${classNames.input} ${classNames.inputCloned}" autocomplete="off" autocapitalize="off" spellcheck="false" role="textbox" aria-autocomplete="list">
|
<input type="text" class="${classNames.input} ${classNames.inputCloned}" autocomplete="off" autocapitalize="off" spellcheck="false" role="textbox" aria-autocomplete="list">
|
||||||
`);
|
`
|
||||||
|
);
|
||||||
},
|
},
|
||||||
dropdown: () => {
|
dropdown: () => {
|
||||||
return strToEl(`
|
return strToEl(`
|
||||||
|
|
|
@ -52,7 +52,6 @@ export const isElement = (o) => {
|
||||||
*/
|
*/
|
||||||
export const extend = function() {
|
export const extend = function() {
|
||||||
let extended = {};
|
let extended = {};
|
||||||
let deep = false;
|
|
||||||
let length = arguments.length;
|
let length = arguments.length;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +62,7 @@ export const extend = function() {
|
||||||
for (let prop in obj) {
|
for (let prop in obj) {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
if (Object.prototype.hasOwnProperty.call(obj, prop)) {
|
||||||
// If deep merge and property is an object, merge properties
|
// If deep merge and property is an object, merge properties
|
||||||
if (deep && isType('Object', obj[prop])) {
|
if (isType('Object', obj[prop])) {
|
||||||
extended[prop] = extend(true, extended[prop], obj[prop]);
|
extended[prop] = extend(true, extended[prop], obj[prop]);
|
||||||
} else {
|
} else {
|
||||||
extended[prop] = obj[prop];
|
extended[prop] = obj[prop];
|
||||||
|
@ -77,11 +76,9 @@ export const extend = function() {
|
||||||
// store argument at position i
|
// store argument at position i
|
||||||
let obj = arguments[i];
|
let obj = arguments[i];
|
||||||
|
|
||||||
// If we are in fact dealing with an object, merge it. Otherwise throw error
|
// If we are in fact dealing with an object, merge it.
|
||||||
if (isType('Object', obj)) {
|
if (isType('Object', obj)) {
|
||||||
merge(obj);
|
merge(obj);
|
||||||
} else {
|
|
||||||
console.error('Custom options must be an object');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
722
index.html
722
index.html
|
@ -1,407 +1,407 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
|
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
|
||||||
<title>Choices</title>
|
<title>Choices</title>
|
||||||
<meta name=description itemprop=description content="A lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.">
|
<meta name=description itemprop=description content="A lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.">
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="assets/images/apple-touch-icon.png">
|
<link rel="apple-touch-icon" sizes="180x180" href="assets/images/apple-touch-icon.png">
|
||||||
<link rel="icon" type="image/png" href="assets/images/favicon-32x32.png" sizes="32x32">
|
<link rel="icon" type="image/png" href="assets/images/favicon-32x32.png" sizes="32x32">
|
||||||
<link rel="icon" type="image/png" href="assets/images/favicon-16x16.png" sizes="16x16">
|
<link rel="icon" type="image/png" href="assets/images/favicon-16x16.png" sizes="16x16">
|
||||||
<link rel="manifest" href="assets/images/manifest.json">
|
<link rel="manifest" href="assets/images/manifest.json">
|
||||||
<link rel="mask-icon" href="assets/images/safari-pinned-tab.svg" color="#00bcd4">
|
<link rel="mask-icon" href="assets/images/safari-pinned-tab.svg" color="#00bcd4">
|
||||||
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
<link rel="shortcut icon" href="assets/images/favicon.ico">
|
||||||
<meta name="msapplication-config" content="/assets/images/browserconfig.xml">
|
<meta name="msapplication-config" content="/assets/images/browserconfig.xml">
|
||||||
<meta name="theme-color" content="#ffffff">
|
<meta name="theme-color" content="#ffffff">
|
||||||
|
|
||||||
<!-- Ignore these -->
|
<!-- Ignore these -->
|
||||||
<link rel="stylesheet" href="assets/styles/css/base.min.css?version=2.0.2">
|
<link rel="stylesheet" href="assets/styles/css/base.min.css?version=2.0.2">
|
||||||
<!-- End ignore these -->
|
<!-- End ignore these -->
|
||||||
|
|
||||||
<!-- Optional includes -->
|
<!-- Optional includes -->
|
||||||
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es5,fetch,Element.prototype.classList,requestAnimationFrame,Node.insertBefore,Node.firstChild"></script>
|
<script src="https://cdn.polyfill.io/v2/polyfill.js?features=es5,fetch,Element.prototype.classList,requestAnimationFrame,Node.insertBefore,Node.firstChild"></script>
|
||||||
<!-- End optional includes -->
|
<!-- End optional includes -->
|
||||||
|
|
||||||
<!-- Choices includes -->
|
<!-- Choices includes -->
|
||||||
<link rel="stylesheet" href="assets/styles/css/choices.min.css?version=2.0.2">
|
<link rel="stylesheet" href="assets/styles/css/choices.min.css?version=2.0.2">
|
||||||
<script src="assets/scripts/dist/choices.min.js?version=2.0.2"></script>
|
<script src="assets/scripts/dist/choices.min.js?version=2.0.2"></script>
|
||||||
<!-- 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">
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<img src="assets/images/logo.svg" alt="Choices.js logo" class="logo hidden-ie">
|
<img src="assets/images/logo.svg" alt="Choices.js logo" class="logo hidden-ie">
|
||||||
<h1 class="visible-ie">Choices.js</h1>
|
<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>
|
<p>Choices.js is a lightweight, configurable select box/text input plugin. Similar to Select2 and Selectize but without the jQuery dependency.</p>
|
||||||
<p>For all config options, visit the <a href="https://github.com/jshjohnson/Choices">GitHub repo</a>.</p>
|
<p>For all config options, visit the <a href="https://github.com/jshjohnson/Choices">GitHub repo</a>.</p>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<h2>Text inputs</h2>
|
<h2>Text inputs</h2>
|
||||||
<label for="choices-text-remove-button">Limited to 5 values with remove button</label>
|
<label for="choices-text-remove-button">Limited to 5 values with remove button</label>
|
||||||
<input class="form-control" id="choices-text-remove-button" type="text" value="preset-1,preset-2" placeholder="Enter something">
|
<input class="form-control" id="choices-text-remove-button" type="text" value="preset-1,preset-2" placeholder="Enter something">
|
||||||
|
|
||||||
<label for="choices-text-unique-values">Unique values only, no pasting</label>
|
<label for="choices-text-unique-values">Unique values only, no pasting</label>
|
||||||
<input class="form-control" id="choices-text-unique-values" type="text" value="preset-1, preset-2" placeholder="This is a placeholder" class="custom class">
|
<input class="form-control" id="choices-text-unique-values" type="text" value="preset-1, preset-2" placeholder="This is a placeholder" class="custom class">
|
||||||
|
|
||||||
<label for="choices-text-email-filter">Email addresses only</label>
|
<label for="choices-text-email-filter">Email addresses only</label>
|
||||||
<input class="form-control" id="choices-text-email-filter" type="text" placeholder="This is a placeholder">
|
<input class="form-control" id="choices-text-email-filter" type="text" placeholder="This is a placeholder">
|
||||||
|
|
||||||
<label for="choices-text-disabled">Disabled</label>
|
<label for="choices-text-disabled">Disabled</label>
|
||||||
<input class="form-control" id="choices-text-disabled" type="text" value="josh@joshuajohnson.co.uk, joe@bloggs.co.uk" placeholder="This is a placeholder">
|
<input class="form-control" id="choices-text-disabled" type="text" value="josh@joshuajohnson.co.uk, joe@bloggs.co.uk" placeholder="This is a placeholder">
|
||||||
|
|
||||||
<label for="choices-text-prepend-append-value">Prepends and appends a value to each items return value</label>
|
<label for="choices-text-prepend-append-value">Prepends and appends a value to each items return value</label>
|
||||||
<input class="form-control" id="choices-text-prepend-append-value" type="text" value="preset-1, preset-2" placeholder="This is a placeholder">
|
<input class="form-control" id="choices-text-prepend-append-value" type="text" value="preset-1, preset-2" placeholder="This is a placeholder">
|
||||||
|
|
||||||
<label for="choices-text-preset-values">Preset values passed through options</label>
|
<label for="choices-text-preset-values">Preset values passed through options</label>
|
||||||
<input class="form-control" id="choices-text-preset-values" type="text" value="olivia@benson.com" placeholder="This is a placeholder">
|
<input class="form-control" id="choices-text-preset-values" type="text" value="olivia@benson.com" placeholder="This is a placeholder">
|
||||||
|
|
||||||
<label for="choices-text-preset-values">Right-to-left</label>
|
<label for="choices-text-preset-values">Right-to-left</label>
|
||||||
<input class="form-control" data-choice id="choices-text-rtl" type="text" value="Value 1, Value 2" dir="rtl">
|
<input class="form-control" data-choice id="choices-text-rtl" type="text" value="Value 1, Value 2" dir="rtl">
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<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>
|
||||||
<select class="form-control" name="choices-multiple-remote-fetch" id="choices-multiple-remote-fetch" multiple></select>
|
<select class="form-control" name="choices-multiple-remote-fetch" id="choices-multiple-remote-fetch" multiple></select>
|
||||||
|
|
||||||
<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 placeholder">
|
||||||
<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-remote-fetch">Options from remote source (Fetch API)</label>
|
<label for="choices-single-remote-fetch">Options from remote source (Fetch API)</label>
|
||||||
<select class="form-control" name="choices-single-remote-fetch" id="choices-single-remote-fetch" placeholder="Pick an Arctic Monkeys record"></select>
|
<select class="form-control" name="choices-single-remote-fetch" id="choices-single-remote-fetch" placeholder="Pick an Arctic Monkeys record"></select>
|
||||||
|
|
||||||
<label for="choices-single-remove-xhr">Options from remote source (XHR) & remove button</label>
|
<label for="choices-single-remove-xhr">Options from remote source (XHR) & remove button</label>
|
||||||
<select class="form-control" name="choices-single-remove-xhr" id="choices-single-remove-xhr" placeholder="Pick a Smiths record"></select>
|
<select class="form-control" name="choices-single-remove-xhr" id="choices-single-remove-xhr" placeholder="Pick a Smiths record"></select>
|
||||||
|
|
||||||
<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>
|
||||||
<select class="form-control" name="choices-single-preset-options" id="choices-single-preset-options" placeholder="This is a placeholder"></select>
|
<select class="form-control" name="choices-single-preset-options" id="choices-single-preset-options" placeholder="This is a placeholder"></select>
|
||||||
|
|
||||||
<label for="choices-single-selected-option">Option selected via config</label>
|
<label for="choices-single-selected-option">Option selected via config</label>
|
||||||
<select class="form-control" name="choices-single-selected-option" id="choices-single-selected-option" placeholder="This is a placeholder"></select>
|
<select class="form-control" name="choices-single-selected-option" id="choices-single-selected-option" placeholder="This is a placeholder"></select>
|
||||||
|
|
||||||
<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>
|
||||||
<script>
|
</div>
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
<script>
|
||||||
var example1 = new Choices(document.getElementById('choices-text-remove-button'), {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
delimiter: ',',
|
var example1 = new Choices(document.getElementById('choices-text-remove-button'), {
|
||||||
editItems: true,
|
delimiter: ',',
|
||||||
maxItemCount: 5,
|
editItems: true,
|
||||||
removeItemButton: true,
|
maxItemCount: 5,
|
||||||
callbackOnHighlightItem: function(id, value, passedInput) {
|
removeItemButton: true,
|
||||||
console.log(value);
|
callbackOnHighlightItem: function(id, value, passedInput) {
|
||||||
},
|
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 states = new Choices(document.getElementById('states'), {
|
var example4 = new Choices('#choices-text-disabled', {
|
||||||
callbackOnChange: function(value) {
|
addItems: false,
|
||||||
if(value === 'New York') {
|
removeItems: false,
|
||||||
boroughs.enable();
|
}).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 {
|
} else {
|
||||||
boroughs.disable();
|
console.error(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
request.send();
|
||||||
var boroughs = new Choices(document.getElementById('boroughs')).disable();
|
|
||||||
});
|
});
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- Google Analytics - Ignore me -->
|
var example12 = new Choices('[data-choice]', {
|
||||||
<script>
|
placeholderValue: 'This is a placeholder set in the config',
|
||||||
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
|
removeButton: true,
|
||||||
ga('create', 'UA-31575166-1', 'auto');
|
});
|
||||||
ga('send', 'pageview');
|
|
||||||
</script>
|
var example13 = new Choices('#choices-single-no-search', {
|
||||||
<script async src='https://www.google-analytics.com/analytics.js'></script>
|
search: false,
|
||||||
<!-- End Google Analytics -->
|
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>
|
||||||
|
|
||||||
|
<!-- 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 -->
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
20
package.json
20
package.json
|
@ -63,14 +63,12 @@
|
||||||
"fuse.js": "^2.2.0"
|
"fuse.js": "^2.2.0"
|
||||||
},
|
},
|
||||||
"npmName": "choices.js",
|
"npmName": "choices.js",
|
||||||
"npmFileMap": [
|
"npmFileMap": [{
|
||||||
{
|
"basePath": "assets",
|
||||||
"basePath": "assets",
|
"files": [
|
||||||
"files": [
|
"scripts/dist/*",
|
||||||
"scripts/dist/*",
|
"styles/css/*",
|
||||||
"styles/css/*",
|
"icons/*"
|
||||||
"icons/*"
|
]
|
||||||
]
|
}]
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
|
16
server.js
16
server.js
|
@ -4,11 +4,11 @@ var config = require('./webpack.config.dev');
|
||||||
var opn = require('opn');
|
var opn = require('opn');
|
||||||
|
|
||||||
new WebpackDevServer(webpack(config), {
|
new WebpackDevServer(webpack(config), {
|
||||||
publicPath: config.output.publicPath,
|
publicPath: config.output.publicPath,
|
||||||
historyApiFallback: true,
|
historyApiFallback: true,
|
||||||
quiet: true, // lets WebpackDashboard do its thing
|
quiet: true, // lets WebpackDashboard do its thing
|
||||||
}).listen(3000, 'localhost', function (err, result) {
|
}).listen(3000, 'localhost', function(err, result) {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
opn('http://localhost:3000');
|
opn('http://localhost:3000');
|
||||||
console.log('Listening at localhost:3000');
|
console.log('Listening at localhost:3000');
|
||||||
});
|
});
|
|
@ -5,34 +5,34 @@ var DashboardPlugin = require('webpack-dashboard/plugin');
|
||||||
var dashboard = new Dashboard();
|
var dashboard = new Dashboard();
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
devtool: 'eval',
|
devtool: 'eval',
|
||||||
entry: [
|
entry: [
|
||||||
'webpack-dev-server/client?http://localhost:3000',
|
'webpack-dev-server/client?http://localhost:3000',
|
||||||
'./assets/scripts/src/choices'
|
'./assets/scripts/src/choices'
|
||||||
],
|
],
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, 'dist'),
|
path: path.join(__dirname, 'dist'),
|
||||||
filename: 'choices.min.js',
|
filename: 'choices.min.js',
|
||||||
publicPath: '/assets/scripts/dist/',
|
publicPath: '/assets/scripts/dist/',
|
||||||
},
|
},
|
||||||
eslint: {
|
eslint: {
|
||||||
configFile: '.eslintrc'
|
configFile: '.eslintrc'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new DashboardPlugin(dashboard.setData),
|
new DashboardPlugin(dashboard.setData),
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
new webpack.HotModuleReplacementPlugin(),
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': {
|
||||||
'NODE_ENV': JSON.stringify('development')
|
'NODE_ENV': JSON.stringify('development')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
loaders: [{
|
loaders: [{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
exclude: /(node_modules|bower_components)/,
|
exclude: /(node_modules|bower_components)/,
|
||||||
loaders: ['babel', 'eslint-loader'],
|
loaders: ['babel', 'eslint-loader'],
|
||||||
include: path.join(__dirname, 'assets/scripts/src')
|
include: path.join(__dirname, 'assets/scripts/src')
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -6,48 +6,48 @@ var banner = `/*! ${ package.name } v${ package.version } | (c) ${ new Date().ge
|
||||||
var minimize = process.argv.indexOf('--minimize') !== -1;
|
var minimize = process.argv.indexOf('--minimize') !== -1;
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
devtool: 'cheap-module-source-map',
|
devtool: 'cheap-module-source-map',
|
||||||
entry: [
|
entry: [
|
||||||
'./assets/scripts/src/choices'
|
'./assets/scripts/src/choices'
|
||||||
],
|
],
|
||||||
output: {
|
output: {
|
||||||
path: path.join(__dirname, '/assets/scripts/dist'),
|
path: path.join(__dirname, '/assets/scripts/dist'),
|
||||||
filename: minimize ? 'choices.min.js' : 'choices.js',
|
filename: minimize ? 'choices.min.js' : 'choices.js',
|
||||||
publicPath: '/assets/scripts/dist/'
|
publicPath: '/assets/scripts/dist/'
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env': {
|
||||||
// This has effect on the react lib size
|
// This has effect on the react lib size
|
||||||
'NODE_ENV': JSON.stringify('production'),
|
'NODE_ENV': JSON.stringify('production'),
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
new wrapperPlugin({
|
new wrapperPlugin({
|
||||||
header: banner,
|
header: banner,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
module: {
|
module: {
|
||||||
loaders: [{
|
loaders: [{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
exclude: /(node_modules|bower_components)/,
|
exclude: /(node_modules|bower_components)/,
|
||||||
loaders: ['babel'],
|
loaders: ['babel'],
|
||||||
include: path.join(__dirname, 'assets/scripts/src')
|
include: path.join(__dirname, 'assets/scripts/src')
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (minimize) {
|
if (minimize) {
|
||||||
config.plugins.unshift(new webpack.optimize.UglifyJsPlugin({
|
config.plugins.unshift(new webpack.optimize.UglifyJsPlugin({
|
||||||
sourceMap: false,
|
sourceMap: false,
|
||||||
mangle: true,
|
mangle: true,
|
||||||
output: {
|
output: {
|
||||||
comments: false
|
comments: false
|
||||||
},
|
},
|
||||||
compress: {
|
compress: {
|
||||||
warnings: false,
|
warnings: false,
|
||||||
screw_ie8: true
|
screw_ie8: true
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = config;
|
module.exports = config;
|
Loading…
Reference in a new issue