set the width of select2 input (through Angular-ui directive)
Solution 1:
In my case the select2 would open correctly if there was zero or more pills.
But if there was one or more pills, and I deleted them all, it would shrink to the smallest width. My solution was simply:
$("#myselect").select2({ width: '100%' });
Solution 2:
You need to specify the attribute width to resolve in order to preserve element width
$(document).ready(function() {
$("#myselect").select2({ width: 'resolve' });
});
Solution 3:
This is an old question but new info is still worth posting...
Starting with Select2 version 3.4.0 there is an attribute dropdownAutoWidth
which solves the problem and handles all the odd cases. Note it is not on by default. It resizes dynamically as the user makes selections, it adds width for allowClear
if that attribute is used, and it handles placeholder text properly too.
$("#some_select_id").select2({
dropdownAutoWidth : true
});
Solution 4:
select2 V4.0.3
<select class="smartsearch" name="search" id="search" style="width:100%;"></select>