select2 - hiding the search box

前端 未结 18 1669
太阳男子
太阳男子 2021-01-29 19:04

For my more significant selects, the search box in Select2 is wonderful. However, in one instance, I have a simple selection of 4 hard-coded choices. In this case, the search bo

相关标签:
18条回答
  • 2021-01-29 19:38

    If the select is show results one have to use this:

    $('#yourSelect2ControlId').select2("close").parent().hide();
    

    it closes the search results box and then set control unvisible

    0 讨论(0)
  • 2021-01-29 19:39

    If you want to hide search for a specific drop down use the id attribute for that.

    $('#select_id').select2({ minimumResultsForSearch: -1 });
    
    0 讨论(0)
  • 2021-01-29 19:42

    @Misha Kobrin's answer work well for me So I have decided to explain it more

    You want to hide the search box you can do it by jQuery.

    for example you have initialized select2 plugin on a drop down having id audience

    element_select = '#audience';// id or class
    $(element_select).select2("close").parent().hide();
    

    The example works on all devices on which select2 works.

    0 讨论(0)
  • 2021-01-29 19:43

    See this thread https://github.com/ivaynberg/select2/issues/489, you can hide the search box by setting minimumResultsForSearch to a negative value.

    $('select').select2({
        minimumResultsForSearch: -1
    });
    
    0 讨论(0)
  • 2021-01-29 19:45
    .no-search .select2-search {
        display:none
    }
    
    $("#test").select2({
        dropdownCssClass : 'no-search'
    }); 
    
    0 讨论(0)
  • 2021-01-29 19:45

    try this CSS

    input[aria-controls=select2-product-type-results]{
      display: none;
    }
    

    this input is search field

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