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) { (function webpackUniversalModuleDefinition(root, factory) {
//CommonJS2 //CommonJS2
if(typeof exports === 'object' && typeof module === 'object') if(typeof exports === 'object' && typeof module === 'object')
@ -3751,24 +3751,14 @@ var Choices = function () {
} }
// Trigger change event // Trigger change event
if (group && group.value) { this.passedElement.triggerEvent(_constants.EVENTS.addItem, {
this.passedElement.triggerEvent(_constants.EVENTS.addItem, { id: id,
id: id, value: passedValue,
value: passedValue, label: passedLabel,
label: passedLabel, customProperties: passedCustomProperties,
customProperties: passedCustomProperties, groupValue: group && group.value ? group.value : undefined,
groupValue: group.value, keyCode: passedKeyCode
keyCode: passedKeyCode });
});
} else {
this.passedElement.triggerEvent(_constants.EVENTS.addItem, {
id: id,
value: passedValue,
label: passedLabel,
customProperties: passedCustomProperties,
keyCode: passedKeyCode
});
}
return this; return this;
} }
@ -4202,7 +4192,7 @@ var Choices = function () {
this._addItem({ this._addItem({
value: foundChoice.value, value: foundChoice.value,
label: foundChoice.label, label: foundChoice.label,
id: foundChoice.id, choiceId: foundChoice.id,
groupId: foundChoice.groupId, groupId: foundChoice.groupId,
customProperties: foundChoice.customProperties, customProperties: foundChoice.customProperties,
placeholder: foundChoice.placeholder, 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"> <meta name="theme-color" content="#ffffff">
<!-- Ignore these --> <!-- 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 --> <!-- End ignore these -->
<!-- Optional includes --> <!-- Optional includes -->
@ -24,8 +24,8 @@
<!-- End optional includes --> <!-- End optional includes -->
<!-- Choices includes --> <!-- Choices includes -->
<link rel="stylesheet" href="assets/styles/choices.min.css?version=4.1.2"> <link rel="stylesheet" href="assets/styles/choices.min.css?version=4.1.3">
<script src="assets/scripts/choices.min.js?version=4.1.2"></script> <script src="assets/scripts/choices.min.js?version=4.1.3"></script>
<!-- End Choices includes --> <!-- End Choices includes -->
<!--[if lt IE 9]> <!--[if lt IE 9]>

View file

@ -185,6 +185,15 @@
</select> </select>
</form> </form>
</div> </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>
</div> </div>
<script> <script>
@ -296,6 +305,8 @@
}); });
new Choices('#choices-within-form'); new Choices('#choices-within-form');
new Choices('#choices-set-choice-by-value').setChoiceByValue('Choice 2');
}); });
</script> </script>
</body> </body>

View file

@ -189,6 +189,15 @@
</select> </select>
</form> </form>
</div> </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>
</div> </div>
<script> <script>
@ -308,6 +317,8 @@
}); });
new Choices('#choices-within-form'); new Choices('#choices-within-form');
new Choices('#choices-set-choice-by-value').setChoiceByValue('Choice 2');
}); });
</script> </script>
</body> </body>