Added keyCode to choice objects

This commit is contained in:
Andrew Whalley 2017-07-19 13:48:46 -04:00
parent a7ee256a85
commit dba6093297
10 changed files with 478 additions and 417 deletions

View file

@ -972,13 +972,13 @@ return /******/ (function(modules) { // webpackBootstrap
// If we are dealing with a select input, we need to create an option first // If we are dealing with a select input, we need to create an option first
// that is then selected. For text inputs we can just add items normally. // that is then selected. For text inputs we can just add items normally.
if (!_this10.isTextElement) { if (!_this10.isTextElement) {
_this10._addChoice(item.value, item.label, true, false, -1, item.customProperties); _this10._addChoice(item.value, item.label, true, false, -1, item.customProperties, null);
} else { } else {
_this10._addItem(item.value, item.label, item.id, undefined, item.customProperties); _this10._addItem(item.value, item.label, item.id, undefined, item.customProperties, null);
} }
} else if (itemType === 'String') { } else if (itemType === 'String') {
if (!_this10.isTextElement) { if (!_this10.isTextElement) {
_this10._addChoice(item, item, true, false, -1); _this10._addChoice(item, item, true, false, -1, null);
} else { } else {
_this10._addItem(item); _this10._addItem(item);
} }
@ -1022,7 +1022,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (foundChoice) { if (foundChoice) {
if (!foundChoice.selected) { if (!foundChoice.selected) {
_this11._addItem(foundChoice.value, foundChoice.label, foundChoice.id, foundChoice.groupId, foundChoice.customProperties); _this11._addItem(foundChoice.value, foundChoice.label, foundChoice.id, foundChoice.groupId, foundChoice.customProperties, foundChoice.keyCode);
} else if (!_this11.config.silent) { } else if (!_this11.config.silent) {
console.warn('Attempting to select choice already selected'); console.warn('Attempting to select choice already selected');
} }
@ -1067,7 +1067,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (result.choices) { if (result.choices) {
_this12._addGroup(result, result.id || null, value, label); _this12._addGroup(result, result.id || null, value, label);
} else { } else {
_this12._addChoice(result[value], result[label], result.selected, result.disabled, undefined, result['customProperties']); _this12._addChoice(result[value], result[label], result.selected, result.disabled, undefined, result['customProperties'], null);
} }
}); });
} }
@ -1307,8 +1307,12 @@ return /******/ (function(modules) { // webpackBootstrap
// If we are clicking on an option // If we are clicking on an option
var id = element.getAttribute('data-id'); var id = element.getAttribute('data-id');
var choice = this.store.getChoiceById(id); var choice = this.store.getChoiceById(id);
var passedKeyCode = activeItems[0].keyCode !== null ? activeItems[0].keyCode : null;
var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState); var hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
// Update choice keyCode
choice.keyCode = passedKeyCode;
(0, _utils.triggerEvent)(this.passedElement, 'choice', { (0, _utils.triggerEvent)(this.passedElement, 'choice', {
choice: choice choice: choice
}); });
@ -1317,7 +1321,7 @@ return /******/ (function(modules) { // webpackBootstrap
var canAddItem = this._canAddItem(activeItems, choice.value); var canAddItem = this._canAddItem(activeItems, choice.value);
if (canAddItem.response) { if (canAddItem.response) {
this._addItem(choice.value, choice.label, choice.id, choice.groupId, choice.customProperties); this._addItem(choice.value, choice.label, choice.id, choice.groupId, choice.customProperties, choice.keyCode);
this._triggerChange(choice.value); this._triggerChange(choice.value);
} }
} }
@ -1482,7 +1486,7 @@ return /******/ (function(modules) { // webpackBootstrap
var groupId = result.id || null; var groupId = result.id || null;
_this15._addGroup(result, groupId, value, label); _this15._addGroup(result, groupId, value, label);
} else { } else {
_this15._addChoice(result[value], result[label], result.selected, result.disabled, undefined, result['customProperties']); _this15._addChoice(result[value], result[label], result.selected, result.disabled, undefined, result['customProperties'], null);
} }
}); });
} else { } else {
@ -1721,6 +1725,8 @@ return /******/ (function(modules) { // webpackBootstrap
// If we have a highlighted choice // If we have a highlighted choice
if (highlighted) { if (highlighted) {
// add enter keyCode value
activeItems[0].keyCode = enterKey;
_this16._handleChoiceAction(activeItems, highlighted); _this16._handleChoiceAction(activeItems, highlighted);
} }
} else if (_this16.isSelectOneElement) { } else if (_this16.isSelectOneElement) {
@ -2307,8 +2313,10 @@ return /******/ (function(modules) { // webpackBootstrap
var choiceId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1; var choiceId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1;
var groupId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1; var groupId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : -1;
var customProperties = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null; var customProperties = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
var keyCode = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
var passedValue = (0, _utils.isType)('String', value) ? value.trim() : value; var passedValue = (0, _utils.isType)('String', value) ? value.trim() : value;
var passedKeyCode = keyCode;
var items = this.store.getItems(); var items = this.store.getItems();
var passedLabel = label || passedValue; var passedLabel = label || passedValue;
var passedOptionId = parseInt(choiceId, 10) || -1; var passedOptionId = parseInt(choiceId, 10) || -1;
@ -2329,7 +2337,7 @@ return /******/ (function(modules) { // webpackBootstrap
passedValue += this.config.appendValue.toString(); passedValue += this.config.appendValue.toString();
} }
this.store.dispatch((0, _index3.addItem)(passedValue, passedLabel, id, passedOptionId, groupId, customProperties)); this.store.dispatch((0, _index3.addItem)(passedValue, passedLabel, id, passedOptionId, groupId, customProperties, passedKeyCode));
if (this.isSelectOneElement) { if (this.isSelectOneElement) {
this.removeActiveItems(id); this.removeActiveItems(id);
@ -2341,13 +2349,15 @@ return /******/ (function(modules) { // webpackBootstrap
id: id, id: id,
value: passedValue, value: passedValue,
label: passedLabel, label: passedLabel,
groupValue: group.value groupValue: group.value,
keyCode: passedKeyCode
}); });
} else { } else {
(0, _utils.triggerEvent)(this.passedElement, 'addItem', { (0, _utils.triggerEvent)(this.passedElement, 'addItem', {
id: id, id: id,
value: passedValue, value: passedValue,
label: passedLabel label: passedLabel,
keyCode: passedKeyCode
}); });
} }
@ -2415,6 +2425,7 @@ return /******/ (function(modules) { // webpackBootstrap
var isDisabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var isDisabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var groupId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1; var groupId = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : -1;
var customProperties = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null; var customProperties = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
var keyCode = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
if (typeof value === 'undefined' || value === null) { if (typeof value === 'undefined' || value === null) {
return; return;
@ -2426,10 +2437,10 @@ return /******/ (function(modules) { // webpackBootstrap
var choiceId = choices ? choices.length + 1 : 1; var choiceId = choices ? choices.length + 1 : 1;
var choiceElementId = this.baseId + '-' + this.idNames.itemChoice + '-' + choiceId; var choiceElementId = this.baseId + '-' + this.idNames.itemChoice + '-' + choiceId;
this.store.dispatch((0, _index3.addChoice)(value, choiceLabel, choiceId, groupId, isDisabled, choiceElementId, customProperties)); this.store.dispatch((0, _index3.addChoice)(value, choiceLabel, choiceId, groupId, isDisabled, choiceElementId, customProperties, keyCode));
if (isSelected) { if (isSelected) {
this._addItem(value, choiceLabel, choiceId, undefined, customProperties); this._addItem(value, choiceLabel, choiceId, undefined, customProperties, keyCode);
} }
} }
@ -4961,7 +4972,8 @@ return /******/ (function(modules) { // webpackBootstrap
label: action.label, label: action.label,
active: true, active: true,
highlighted: false, highlighted: false,
customProperties: action.customProperties customProperties: action.customProperties,
keyCode: null
}]); }]);
return newState.map(function (item) { return newState.map(function (item) {
@ -5077,7 +5089,8 @@ return /******/ (function(modules) { // webpackBootstrap
selected: false, selected: false,
active: true, active: true,
score: 9999, score: 9999,
customProperties: action.customProperties customProperties: action.customProperties,
keyCode: null
}]); }]);
} }
@ -5174,7 +5187,7 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(exports, "__esModule", { Object.defineProperty(exports, "__esModule", {
value: true value: true
}); });
var addItem = exports.addItem = function addItem(value, label, id, choiceId, groupId, customProperties) { var addItem = exports.addItem = function addItem(value, label, id, choiceId, groupId, customProperties, keyCode) {
return { return {
type: 'ADD_ITEM', type: 'ADD_ITEM',
value: value, value: value,
@ -5182,7 +5195,8 @@ return /******/ (function(modules) { // webpackBootstrap
id: id, id: id,
choiceId: choiceId, choiceId: choiceId,
groupId: groupId, groupId: groupId,
customProperties: customProperties customProperties: customProperties,
keyCode: keyCode
}; };
}; };
@ -5202,7 +5216,7 @@ return /******/ (function(modules) { // webpackBootstrap
}; };
}; };
var addChoice = exports.addChoice = function addChoice(value, label, id, groupId, disabled, elementId, customProperties) { var addChoice = exports.addChoice = function addChoice(value, label, id, groupId, disabled, elementId, customProperties, keyCode) {
return { return {
type: 'ADD_CHOICE', type: 'ADD_CHOICE',
value: value, value: value,
@ -5211,7 +5225,8 @@ return /******/ (function(modules) { // webpackBootstrap
groupId: groupId, groupId: groupId,
disabled: disabled, disabled: disabled,
elementId: elementId, elementId: elementId,
customProperties: customProperties customProperties: customProperties,
keyCode: keyCode
}; };
}; };

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
export const addItem = (value, label, id, choiceId, groupId, customProperties) => { export const addItem = (value, label, id, choiceId, groupId, customProperties, keyCode) => {
return { return {
type: 'ADD_ITEM', type: 'ADD_ITEM',
value, value,
@ -6,7 +6,8 @@ export const addItem = (value, label, id, choiceId, groupId, customProperties) =
id, id,
choiceId, choiceId,
groupId, groupId,
customProperties customProperties,
keyCode
}; };
}; };
@ -26,7 +27,7 @@ export const highlightItem = (id, highlighted) => {
}; };
}; };
export const addChoice = (value, label, id, groupId, disabled, elementId, customProperties) => { export const addChoice = (value, label, id, groupId, disabled, elementId, customProperties, keyCode) => {
return { return {
type: 'ADD_CHOICE', type: 'ADD_CHOICE',
value, value,
@ -35,7 +36,8 @@ export const addChoice = (value, label, id, groupId, disabled, elementId, custom
groupId, groupId,
disabled, disabled,
elementId: elementId, elementId: elementId,
customProperties customProperties,
keyCode
}; };
}; };

View file

@ -838,7 +838,8 @@ class Choices {
true, true,
false, false,
-1, -1,
item.customProperties item.customProperties,
null
); );
} else { } else {
this._addItem( this._addItem(
@ -846,7 +847,8 @@ class Choices {
item.label, item.label,
item.id, item.id,
undefined, undefined,
item.customProperties item.customProperties,
null
); );
} }
} else if (itemType === 'String') { } else if (itemType === 'String') {
@ -856,7 +858,8 @@ class Choices {
item, item,
true, true,
false, false,
-1 -1,
null
); );
} else { } else {
this._addItem(item); this._addItem(item);
@ -901,7 +904,8 @@ class Choices {
foundChoice.label, foundChoice.label,
foundChoice.id, foundChoice.id,
foundChoice.groupId, foundChoice.groupId,
foundChoice.customProperties foundChoice.customProperties,
foundChoice.keyCode
); );
} else if (!this.config.silent) { } else if (!this.config.silent) {
console.warn('Attempting to select choice already selected'); console.warn('Attempting to select choice already selected');
@ -951,7 +955,8 @@ class Choices {
result.selected, result.selected,
result.disabled, result.disabled,
undefined, undefined,
result['customProperties'] result['customProperties'],
null
); );
} }
}); });
@ -1158,8 +1163,12 @@ class Choices {
// If we are clicking on an option // If we are clicking on an option
const id = element.getAttribute('data-id'); const id = element.getAttribute('data-id');
const choice = this.store.getChoiceById(id); const choice = this.store.getChoiceById(id);
const passedKeyCode = activeItems[0].keyCode !== null ? activeItems[0].keyCode : null
const hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState); const hasActiveDropdown = this.dropdown.classList.contains(this.config.classNames.activeState);
// Update choice keyCode
choice.keyCode = passedKeyCode
triggerEvent(this.passedElement, 'choice', { triggerEvent(this.passedElement, 'choice', {
choice, choice,
}); });
@ -1173,7 +1182,8 @@ class Choices {
choice.label, choice.label,
choice.id, choice.id,
choice.groupId, choice.groupId,
choice.customProperties choice.customProperties,
choice.keyCode
); );
this._triggerChange(choice.value); this._triggerChange(choice.value);
} }
@ -1346,7 +1356,8 @@ class Choices {
result.selected, result.selected,
result.disabled, result.disabled,
undefined, undefined,
result['customProperties'] result['customProperties'],
null
); );
} }
}); });
@ -1565,6 +1576,8 @@ class Choices {
// If we have a highlighted choice // If we have a highlighted choice
if (highlighted) { if (highlighted) {
// add enter keyCode value
activeItems[0].keyCode = enterKey
this._handleChoiceAction(activeItems, highlighted); this._handleChoiceAction(activeItems, highlighted);
} }
@ -2102,8 +2115,9 @@ class Choices {
* @return {Object} Class instance * @return {Object} Class instance
* @public * @public
*/ */
_addItem(value, label = null, choiceId = -1, groupId = -1, customProperties = null) { _addItem(value, label = null, choiceId = -1, groupId = -1, customProperties = null, keyCode = null) {
let passedValue = isType('String', value) ? value.trim() : value; let passedValue = isType('String', value) ? value.trim() : value;
let passedKeyCode = keyCode
const items = this.store.getItems(); const items = this.store.getItems();
const passedLabel = label || passedValue; const passedLabel = label || passedValue;
const passedOptionId = parseInt(choiceId, 10) || -1; const passedOptionId = parseInt(choiceId, 10) || -1;
@ -2124,7 +2138,7 @@ class Choices {
passedValue += this.config.appendValue.toString(); passedValue += this.config.appendValue.toString();
} }
this.store.dispatch(addItem(passedValue, passedLabel, id, passedOptionId, groupId, customProperties)); this.store.dispatch(addItem(passedValue, passedLabel, id, passedOptionId, groupId, customProperties, passedKeyCode));
if (this.isSelectOneElement) { if (this.isSelectOneElement) {
this.removeActiveItems(id); this.removeActiveItems(id);
@ -2137,12 +2151,14 @@ class Choices {
value: passedValue, value: passedValue,
label: passedLabel, label: passedLabel,
groupValue: group.value, groupValue: group.value,
keyCode: passedKeyCode
}); });
} else { } else {
triggerEvent(this.passedElement, 'addItem', { triggerEvent(this.passedElement, 'addItem', {
id, id,
value: passedValue, value: passedValue,
label: passedLabel, label: passedLabel,
keyCode: passedKeyCode
}); });
} }
@ -2198,7 +2214,7 @@ class Choices {
* @return * @return
* @private * @private
*/ */
_addChoice(value, label = null, isSelected = false, isDisabled = false, groupId = -1, customProperties = null) { _addChoice(value, label = null, isSelected = false, isDisabled = false, groupId = -1, customProperties = null, keyCode = null) {
if (typeof value === 'undefined' || value === null) { if (typeof value === 'undefined' || value === null) {
return; return;
} }
@ -2216,7 +2232,8 @@ class Choices {
groupId, groupId,
isDisabled, isDisabled,
choiceElementId, choiceElementId,
customProperties customProperties,
keyCode
)); ));
if (isSelected) { if (isSelected) {
@ -2225,7 +2242,8 @@ class Choices {
choiceLabel, choiceLabel,
choiceId, choiceId,
undefined, undefined,
customProperties customProperties,
keyCode
); );
} }
} }

View file

@ -16,7 +16,8 @@ const choices = (state = [], action) => {
selected: false, selected: false,
active: true, active: true,
score: 9999, score: 9999,
customProperties: action.customProperties customProperties: action.customProperties,
keyCode: null
}]; }];
} }

View file

@ -10,7 +10,8 @@ const items = (state = [], action) => {
label: action.label, label: action.label,
active: true, active: true,
highlighted: false, highlighted: false,
customProperties: action.customProperties customProperties: action.customProperties,
keyCode: null
}]; }];
return newState.map((item) => { return newState.map((item) => {

View file

@ -1,5 +1,6 @@
<!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">
@ -24,7 +25,7 @@
<!-- Choices includes --> <!-- Choices includes -->
<link rel="stylesheet" href="assets/styles/css/choices.min.css?version=2.8.8"> <link rel="stylesheet" href="assets/styles/css/choices.min.css?version=2.8.8">
<script src="assets/scripts/dist/choices.min.js?version=2.8.8"></script> <script src="assets/scripts/dist/choices.js?version=2.8.8"></script>
<!-- End Choices includes --> <!-- End Choices includes -->
<!--[if lt IE 9]> <!--[if lt IE 9]>
@ -34,6 +35,7 @@
</style> </style>
<![endif]--> <![endif]-->
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<div class="section"> <div class="section">
@ -41,7 +43,8 @@
<img src="assets/images/logo.svg" alt="Choices.js logo" class="logo__img hidden-ie"> <img src="assets/images/logo.svg" alt="Choices.js logo" class="logo__img hidden-ie">
<h1 class="visible-ie">Choices.js</h1> <h1 class="visible-ie">Choices.js</h1>
</a> </a>
<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>
@ -51,7 +54,8 @@
<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">
@ -75,7 +79,8 @@
<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-trigger name="choices-multiple-default" id="choices-multiple-default" placeholder="This is a placeholder" multiple> <select class="form-control" data-trigger 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>
@ -83,7 +88,8 @@
</select> </select>
<label for="choices-multiple-remove-button">With remove button</label> <label for="choices-multiple-remove-button">With remove button</label>
<select class="form-control" name="choices-multiple-remove-button" id="choices-multiple-remove-button" placeholder="This is a placeholder" multiple> <select class="form-control" name="choices-multiple-remove-button" id="choices-multiple-remove-button" 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>
@ -91,7 +97,8 @@
</select> </select>
<label for="choices-multiple-groups">Option groups</label> <label for="choices-multiple-groups">Option groups</label>
<select class="form-control" name="choices-multiple-groups" id="choices-multiple-groups" placeholder="This is a placeholder" multiple> <select class="form-control" 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>
@ -130,7 +137,8 @@
<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-trigger name="choices-multiple-rtl" id="choices-multiple-rtl" placeholder="This is a placeholder" multiple dir="rtl"> <select class="form-control" data-trigger 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>
@ -194,7 +202,8 @@
</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-trigger name="choices-single-rtl" id="choices-single-rtl" placeholder="This is a placeholder" dir="rtl"> <select class="form-control" data-trigger 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>
@ -242,7 +251,8 @@
<option value="Vue">Vue</option> <option value="Vue">Vue</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>
@ -444,9 +454,11 @@
choices: [ choices: [
{ value: 'One', label: 'Label One', selected: true }, { value: 'One', label: 'Label One', selected: true },
{ value: 'Two', label: 'Label Two', disabled: true }, { value: 'Two', label: 'Label Two', disabled: true },
{value: 'Three', label: 'Label Three', customProperties: { {
value: 'Three', label: 'Label Three', customProperties: {
description: 'This option is fantastic' description: 'This option is fantastic'
}}, }
},
], ],
}).setValueByChoice('Two'); }).setValueByChoice('Two');
@ -504,6 +516,10 @@
var boroughs = new Choices(document.getElementById('boroughs')).disable(); var boroughs = new Choices(document.getElementById('boroughs')).disable();
}); });
document.getElementById('choices-single-default').addEventListener('addItem', function (e) {
console.log(e)
})
</script> </script>
<!-- Google Analytics - Ignore me --> <!-- Google Analytics - Ignore me -->
@ -515,4 +531,5 @@
<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 -->
</body> </body>
</html> </html>

View file

@ -14,7 +14,8 @@
"css:min": "csso assets/styles/css/base.css assets/styles/css/base.min.css && csso assets/styles/css/choices.css assets/styles/css/choices.min.css", "css:min": "csso assets/styles/css/base.css assets/styles/css/base.min.css && csso assets/styles/css/choices.css assets/styles/css/choices.min.css",
"js:build": "concurrently --prefix-colors yellow,green \"webpack --minimize --config webpack.config.prod.js\" \"webpack --config webpack.config.prod.js\"", "js:build": "concurrently --prefix-colors yellow,green \"webpack --minimize --config webpack.config.prod.js\" \"webpack --config webpack.config.prod.js\"",
"version": "node version.js --current $npm_package_version --new $npm_config_newVersion", "version": "node version.js --current $npm_package_version --new $npm_config_newVersion",
"postversion": "npm run js:build" "postversion": "npm run js:build",
"dev": "dev"
}, },
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -975,7 +975,8 @@ describe('Choices', () => {
label: 'label', label: 'label',
customProperties: { customProperties: {
foo: 'bar' foo: 'bar'
} },
keyCode: null
}; };
const expectedState = [{ const expectedState = [{
@ -986,7 +987,8 @@ describe('Choices', () => {
label: randomItem.label, label: randomItem.label,
active: true, active: true,
highlighted: false, highlighted: false,
customProperties: randomItem.customProperties customProperties: randomItem.customProperties,
keyCode: randomItem.keyCode
}]; }];
const action = addItemAction( const action = addItemAction(
@ -995,7 +997,8 @@ describe('Choices', () => {
randomItem.id, randomItem.id,
randomItem.choiceId, randomItem.choiceId,
randomItem.groupId, randomItem.groupId,
randomItem.customProperties randomItem.customProperties,
randomItem.keyCode
); );
expect(itemReducer([], action)).toEqual(expectedState); expect(itemReducer([], action)).toEqual(expectedState);
@ -1011,7 +1014,8 @@ describe('Choices', () => {
disabled: false, disabled: false,
customProperties: { customProperties: {
foo: 'bar' foo: 'bar'
} },
keyCode: null
}; };
const expectedState = [{ const expectedState = [{
@ -1024,7 +1028,8 @@ describe('Choices', () => {
selected: false, selected: false,
active: true, active: true,
score: 9999, score: 9999,
customProperties: randomChoice.customProperties customProperties: randomChoice.customProperties,
keyCode: randomChoice.keyCode
}]; }];
const action = addChoiceAction( const action = addChoiceAction(
@ -1034,7 +1039,8 @@ describe('Choices', () => {
randomChoice.groupId, randomChoice.groupId,
randomChoice.disabled, randomChoice.disabled,
randomChoice.elementId, randomChoice.elementId,
randomChoice.customProperties randomChoice.customProperties,
randomChoice.keyCode
); );
expect(choiceReducer([], action)).toEqual(expectedState); expect(choiceReducer([], action)).toEqual(expectedState);