omriman12
omriman12

Reputation: 1690

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.

Upvotes: 3

Views: 2309

Answers (1)

Milind Anantwar
Milind Anantwar

Reputation: 82241

You need to refresh multiselect after appending the options dynamically:

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

Upvotes: 4

Related Questions