Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap multiselect dynamically selecting dynamically added fields not working

I have my select:

<select id="fields_u" multiple="multiple"></select>

I appended the fields dynamically:

$('#fields_u').append(fields_html);
//or
$('#example-select').append($('<option>', {
    value: 'optionValue',
    text: 'optionText'
}));

Start the plugin:

$('#fields_u').multiselect();

Trying to select:

$('#fields_u').multiselect('select', ['0', '1'...]);

Not working...

This worked for me when the fields where on the DOM.

Is it a known issue?

EDIT! Works, very sorry, silly me. I was sure you put the fields indexes in the select and not the fields names.

like image 456
omriman12 Avatar asked Aug 03 '26 13:08

omriman12


1 Answers

You need to refresh multiselect after appending the options dynamically:

$('#fields_u').multiselect('refresh');
like image 190
Milind Anantwar Avatar answered Aug 07 '26 00:08

Milind Anantwar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!