I have problem making this plunkr (select2 + angulat-ui) work.
http://plnkr.co/edit/NkdWUO?p=preview
In local setup, I get the select2 work, but I cannot set
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%' });
select2 V4.0.3
<select class="smartsearch" name="search" id="search" style="width:100%;"></select>
You can try like this. It works for me
$("#MISSION_ID").select2();
On hide/show or ajax request, we have to reinitialize the select2 plugin
For example:
$("#offialNumberArea").show();
$("#eventNameArea").hide();
$('.selectCriteria').change(function(){
var thisVal = $(this).val();
if(thisVal == 'sailor'){
$("#offialNumberArea").show();
$("#eventNameArea").hide();
}
else
{
$("#offialNumberArea").hide();
$("#eventNameArea").show();
$("#MISSION_ID").select2();
}
});
You need to specify the attribute width to resolve in order to preserve element width
$(document).ready(function() {
$("#myselect").select2({ width: 'resolve' });
});
add method container css in your script like this :
$("#your_select_id").select2({
containerCss : {"display":"block"}
});
it will set your select's width same as width your div.
Add width resolve option to your select2 function
$(document).ready(function() {
$("#myselect").select2({ width: 'resolve' });
});
After add below CSS to your stylesheet
.select2-container {
width: 100% !important;
}
It will sort the issue