mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-18 05:26:35 +02:00
Allow empty values
This commit is contained in:
parent
6c29011d9b
commit
135ca8c1f8
|
@ -1940,7 +1940,7 @@ class Choices {
|
|||
* @private
|
||||
*/
|
||||
_addChoice(isSelected, isDisabled, value, label, groupId = -1) {
|
||||
if (!value) return;
|
||||
if (typeof value === 'undefined' || value === null) return;
|
||||
|
||||
// Generate unique id
|
||||
const choices = this.store.getChoices();
|
||||
|
|
|
@ -640,6 +640,21 @@ describe('Choices', () => {
|
|||
expect(choices[choices.length - 2].value).toEqual('Child Five');
|
||||
});
|
||||
|
||||
it('should handle setChoices() with blank values', function() {
|
||||
this.choices.setChoices([{
|
||||
label: 'Choice one',
|
||||
value: 'one'
|
||||
}, {
|
||||
label: 'Choice two',
|
||||
value: ''
|
||||
}], 'value', 'label', true);
|
||||
|
||||
|
||||
const choices = this.choices.currentState.choices;
|
||||
expect(choices[0].value).toEqual('one');
|
||||
expect(choices[1].value).toEqual('');
|
||||
});
|
||||
|
||||
it('should handle clearStore()', function() {
|
||||
this.choices.clearStore();
|
||||
|
||||
|
|
Loading…
Reference in a new issue