select2 - hiding the search box

前端 未结 18 1667
太阳男子
太阳男子 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:31

    If you have multi attribute in your select, this dirty hack works:

    var multipleSelect = $('select[name="list_type"]');
    multipleSelect.select2();
    multipleSelect.parent().find('.select2-search--inline').remove();
    multipleSelect.on('change', function(){
        multipleSelect.parent().find('.select2-search--inline').remove();
    });
    

    see docs here https://select2.org/searching#limiting-display-of-the-search-box-to-large-result-sets

提交回复
热议问题