Add option and select option
I want one of them to be selected after this command. Is there any way to do this?
select.addOption([
{
title: "James Collins",
val: "1",
options: {
icon: img,
selected: true <------------- example
}
}
Hey @yunusemrek32,
Are you using a single or multiple select?
If your not using multiple select, you could do something like this: (This is a workaround that doesn't use any of the functions within Preline Advanced Select. - This basically destroys the instance, creates a new HTMLOptionElement, appends it and then makes the select into an Preline Advanced Select)
const select = window.HSSelect.getInstance('prelineSelect');
// Destroy and reinitialize the select.
select.destroy();
// Add option
const option = new Option(
'James Collins', // value.name,
'4', // value.id,
false, // This is if the options is default selected or not.
true // value.selected
);
document.getElementById('prelineSelect').appendChild(option);
new HSSelect('prelineSelect');
If it is a multiple select, I can't help currently, see #335
Hey @yunusemrek32, @dotmra - our team just released version 2.4.0, which now includes this option.