user1841702
user1841702

Reputation: 2763

Adding form elements dynamically to Bootstrap multiselect library

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

Answers (1)

Francesco Borzi
Francesco Borzi

Reputation: 61954

$('#example-getting-started').append($('<option>', {
      value: 'optionValue',
      text : 'optionText'
    }));

then:

$('#example-getting-started').multiselect('rebuild');

Upvotes: 2

Related Questions