Prevent select2 from autmatically focussing its search-input when dropdown is opened

后端 未结 10 533
野性不改
野性不改 2021-01-11 16:02

I\'m looking for a way to prevent select2\'s search-input being automatically focussed when the select2-dropdown is opened. I know this is select2\'s intended default behavi

10条回答
  •  余生分开走
    2021-01-11 16:45

    Ok, I am not sure if changing the focus is possible unless you change the select2 script itself (I could be wrong about this though). As a workaround what you could do is hide the search box by setting minimumResultsForSearch property to a negative value.

    
    

    And then:

    $(document).ready(function() {
       $('#test').select2({
          minimumResultsForSearch: -1
       }); 
    });
    

    Fiddle

提交回复
热议问题