preline icon indicating copy to clipboard operation
preline copied to clipboard

Add option and select option

Open yunusemrek32 opened this issue 1 year ago • 1 comments

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 } }

yunusemrek32 avatar Mar 28 '24 23:03 yunusemrek32

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

dotmra avatar Apr 08 '24 12:04 dotmra

Hey @yunusemrek32, @dotmra - our team just released version 2.4.0, which now includes this option.

jahaganiev avatar Jul 22 '24 19:07 jahaganiev