I got a dropdown as follows
<select class="selectpicker" multiple>
<optgroup label="option 1">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</optgroup>
<optgroup label="option 2">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</optgroup>
</select>
I want to select only from one optgroup, whn I try to select option from another optgroup, need to deselect/ not allow to select if one optgroup already has an option selected. I tried changed.bs.select event to get the opt group index but not sure how to achieve this, any help?
$dropdown.on("changed.bs.select", "select", function (){
var $option = $(this).find("option:selected", this);
var optGroup = $option.closest("optgroup").index();
})
Try this http://jsfiddle.net/g9byn80a/