Select2 open dropdown on focus text input

6,748 views
Skip to first unread message

Saeide Hatamikhah

unread,
Jul 15, 2015, 3:42:41 AM7/15/15
to sel...@googlegroups.com

I have a form with one text input and one select2 element (Version 4.0.0). I want when focus on text input, the select2 open.

Here’s what I’ve tried :

<select list="userAccountsMap.values" listKey="accountNo" listValue="accountNo"/>
<input id="destinationAccount" type="text" name="destinationAccount">

<script type="text/javascript">

('select').each(function( index ) {
         $(this).select2();
     }
});

$("#destinationAccount").focus(function () {    
   $("select").trigger('select2:open');
});

</script>

But it is not work. I don't understand what my problem is.

Message has been deleted

Saeide Hatamikhah

unread,
Jul 20, 2015, 2:29:52 AM7/20/15
to sel...@googlegroups.com

Kevin Brown

unread,
Jul 31, 2015, 3:43:54 PM7/31/15
to sel...@googlegroups.com

Select2 4.0.0 does not trigger the `focus` event, and as a result is not possible to automatically open the dropdown when the input is focused.

We are tracking the progress of standard events at https://github.com/select2/select2/issues/1908.


--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

Mohammad Abubakar Akram

unread,
May 10, 2023, 3:32:39 AM5/10/23
to select2
$(document).on('select2:open', () => {
document.querySelector('.select2-container--open .select2-search__field').focus();
});
Reply all
Reply to author
Forward
0 new messages