Select2 open dropdown on focus

前端 未结 16 2207
陌清茗
陌清茗 2020-12-05 00:21

I have a form with multiple text inputs and some select2 elements. Using the keyboard to tab between fields works fine - the Select2 element behaves like a form element and

16条回答
  •  一整个雨季
    2020-12-05 00:53

    Somehow select2Focus didn't work here with empty selection, couldn't figured out the issue, therefore I added manual control when after focus event auto open get's triggered.

    Here is coffeescript:

    $("#myid").select2()
      .on 'select2-blur', ->
        $(this).data('select2-auto-open', 'true')
      .on 'select2-focus', ->
        $(this).data('select2').open() if $(this).data('select2-auto-open') != 'false'
      .on 'select2-selecting', ->
        $(this).data('select2-auto-open', 'false')
    

提交回复
热议问题