Choices
Choices copied to clipboard
How to add an Item programmatically ?
How to add an Item (see terminology) programmatically ? I need to use it, when user clicks something outside choices container.
Try using setChoices method:
first initialize choices select on a variable.
let select = new Choices({...optionsHere});
then upon loading the dom call the method:
select.setChoices(arrayOfValues, 'value', 'label', false)
note: arrayOfValues is used if using multiple select otherwise just pass in the id value of the option you wanted to be selected.
gotchas: this method currently have a bug where the pre selected items cannot be deselected using the close button and there is an open pull request to fix this issue. I'm also looking for a workaround this at the moment.