How to realize selection of an item from choices element using jshjohnson choices library.
Code:
let vehicleModel = document.getElementById('vehicleModel');
let choiceProps = {
renderChoiceLimit: -1,
maxItemCount: -1,
silent: false,
removeItems: false,
editItems: false,
searchEnabled: true,
searchFields: 'label',
searchResultLimit: 6,
itemSelectText: 'Кликните для выбора',
classNames: {
listSingle: 'form-control pl-3',
containerInner: 'p-0'
},
};
const modelChoices = new Choices(vehicleModel, choiceProps);
let models = []; // I get the values from axios to pass them as paramater
modelChoices.setChoices(models, 'value', 'label', false);
After I initiated choices element in another part of code i have to select a value with autofilling function
const fillModelWithValue = (modelName) => {
let modelCoices = document.getElementById('vehicleModel').setChoiceByValue(modelName);
}
This code doesn't work. But how can I realize this functionality?