set the width of select2 input (through Angular-ui directive)

前端 未结 12 1716
名媛妹妹
名媛妹妹 2020-12-22 20:14

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

相关标签:
12条回答
  • 2020-12-22 21:05

    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%' });      
    
    0 讨论(0)
  • 2020-12-22 21:06

    select2 V4.0.3

    <select class="smartsearch" name="search" id="search" style="width:100%;"></select>
    
    0 讨论(0)
  • 2020-12-22 21:07

    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();
        }
    });
    
    0 讨论(0)
  • 2020-12-22 21:10

    You need to specify the attribute width to resolve in order to preserve element width

    $(document).ready(function() { 
        $("#myselect").select2({ width: 'resolve' });           
    });
    
    0 讨论(0)
  • 2020-12-22 21:10

    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.

    0 讨论(0)
  • 2020-12-22 21:11

    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

    0 讨论(0)
提交回复
热议问题