How do i set focus to select2?

How do i set focus to select2?

humbertobhumbertob Posts: 2Questions: 1Answers: 0

I need to focus on a control select2 which allows me to enter text immediately

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    I'm not sure why that isn't immediately working to be honest. Let me look into it and get back to you.

    Allan

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Sorry for the long delay in replying here. Try adding the following to the Select2 plug-in definition:

        focus: function ( conf ) {
            conf._input.select2('open');
        }
    

    If you need to focus on a Select2 form as soon as the form opens you'd need to add a setTimeout into that function - I'm still looking into why.

    Allan

  • humbertobhumbertob Posts: 2Questions: 1Answers: 0

    I did this

    formOptions: {
       main: {
          focus: 1
       }
    } 
    

    and control open but I have to click to start writing

This discussion has been closed.