I have a multivalue select, and I want to set the restriction on number of selected items using the select2
library.
Documentation says that I should set maximumSelectionSize
during the object initialization. Unfortunately, the following code doesn't work:
$(document).ready(function () {
$("#select_demo").select2({
maximumSelectionSize: 3
});
});
My html selectbox:
<div class="form-group">
<select id="select_demo" multiple="multiple" class="form-control select2 select2-container-multi">
<optgroup label="One">
<option>one</option>
<option>two</option>
<option>three</option>
<option>four</option>
</optgroup>
<optgroup label="Two">
<option>one2</option>
<option>two2</option>
</optgroup>
<optgroup label="Three">
<option>one3</option>
<option>two3</option>
<option>three3</option>
<option>four3</option>
</optgroup>
</select>
</div>
http://jsfiddle.net/x4oqL1jr/2/
What is wrong with this chunk of code?