Fix set choice by value bug (#471)

* Resolve bug with setChoiceByValue not removing choice from dropdown

* 4.1.3

* Version 4.1.3
This commit is contained in:
Josh Johnson 2018-11-25 12:48:49 +00:00 committed by GitHub
parent 3fc7d35758
commit 7f348b4b2b
6 changed files with 38 additions and 26 deletions

View file

@ -1,4 +1,4 @@
/*! choices.js v4.1.2 | (c) 2018 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
/*! choices.js v4.1.3 | (c) 2018 Josh Johnson | https://github.com/jshjohnson/Choices#readme */
(function webpackUniversalModuleDefinition(root, factory) {
//CommonJS2
if(typeof exports === 'object' && typeof module === 'object')
@ -3751,24 +3751,14 @@ var Choices = function () {
}
// Trigger change event
if (group && group.value) {
this.passedElement.triggerEvent(_constants.EVENTS.addItem, {
id: id,
value: passedValue,
label: passedLabel,
customProperties: passedCustomProperties,
groupValue: group.value,
keyCode: passedKeyCode
});
} else {
this.passedElement.triggerEvent(_constants.EVENTS.addItem, {
id: id,
value: passedValue,
label: passedLabel,
customProperties: passedCustomProperties,
keyCode: passedKeyCode
});
}
this.passedElement.triggerEvent(_constants.EVENTS.addItem, {
id: id,
value: passedValue,
label: passedLabel,
customProperties: passedCustomProperties,
groupValue: group && group.value ? group.value : undefined,
keyCode: passedKeyCode
});
return this;
}
@ -4202,7 +4192,7 @@ var Choices = function () {
this._addItem({
value: foundChoice.value,
label: foundChoice.label,
id: foundChoice.id,
choiceId: foundChoice.id,
groupId: foundChoice.groupId,
customProperties: foundChoice.customProperties,
placeholder: foundChoice.placeholder,

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -16,7 +16,7 @@
<meta name="theme-color" content="#ffffff">
<!-- Ignore these -->
<link rel="stylesheet" href="assets/styles/base.min.css?version=4.1.2">
<link rel="stylesheet" href="assets/styles/base.min.css?version=4.1.3">
<!-- End ignore these -->
<!-- Optional includes -->
@ -24,8 +24,8 @@
<!-- End optional includes -->
<!-- Choices includes -->
<link rel="stylesheet" href="assets/styles/choices.min.css?version=4.1.2">
<script src="assets/scripts/choices.min.js?version=4.1.2"></script>
<link rel="stylesheet" href="assets/styles/choices.min.css?version=4.1.3">
<script src="assets/scripts/choices.min.js?version=4.1.3"></script>
<!-- End Choices includes -->
<!--[if lt IE 9]>

View file

@ -185,6 +185,15 @@
</select>
</form>
</div>
<div data-test-hook="set-choice-by-value">
<label for="choices-set-choice-by-value">Dynamically set choice by value</label>
<select class="form-control" name="choices-set-choice-by-value" id="choices-set-choice-by-value" multiple>
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
<option value="Choice 3">Choice 3</option>
</select>
</div>
</div>
</div>
<script>
@ -296,6 +305,8 @@
});
new Choices('#choices-within-form');
new Choices('#choices-set-choice-by-value').setChoiceByValue('Choice 2');
});
</script>
</body>

View file

@ -189,6 +189,15 @@
</select>
</form>
</div>
<div data-test-hook="set-choice-by-value">
<label for="choices-set-choice-by-value">Dynamically set choice by value</label>
<select class="form-control" name="choices-set-choice-by-value" id="choices-set-choice-by-value">
<option value="Choice 1">Choice 1</option>
<option value="Choice 2">Choice 2</option>
<option value="Choice 3">Choice 3</option>
</select>
</div>
</div>
</div>
<script>
@ -308,6 +317,8 @@
});
new Choices('#choices-within-form');
new Choices('#choices-set-choice-by-value').setChoiceByValue('Choice 2');
});
</script>
</body>