Reputation: 2763
I am trying to use the Bootstrap multiselect library (http://davidstutz.github.io/bootstrap-multiselect/#getting-started ) to use form controls, namely checkboxes in a Bootstrap dropdown. I am trying to populate options dynamically as opposed to the example. However, adding elements dynamically causes the dropdown to close immediately after selecting a form element (perhaps this has to do with event propagation) and does not allow me to manipulate other checkboxes. How do I resolve this issue ?
Specifically how do I populate elements dynamically into the select tag ? The example:
<select id="example-getting-started" multiple="multiple">
<option value="cheese">Cheese</option>
<option value="tomatoes">Tomatoes</option>
<option value="mozarella">Mozzarella</option>
<option value="mushrooms">Mushrooms</option>
<option value="pepperoni">Pepperoni</option>
<option value="onions">Onions</option>
</select>
Any help with this would be greatly appreciated !
Upvotes: 0
Views: 4822
Reputation: 61954
$('#example-getting-started').append($('<option>', {
value: 'optionValue',
text : 'optionText'
}));
then:
$('#example-getting-started').multiselect('rebuild');
Upvotes: 2