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

后端 未结 10 497
野性不改
野性不改 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:35

    This worked for me on select2 v4:

    // keep search input, but avoid autofocus on dropdown open
    $('#research .filter').on('select2:open', function (e) {
        $('.select2-search input').prop('focus',false);
    });
    

    credit goes to this github comment

提交回复
热议问题