Select2 open dropdown on focus text input

ยอดดู 6,725 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Saeide Hatamikhah

ยังไม่อ่าน,
15 ก.ค. 2558 03:42:4115/7/58
ถึง 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.

ข้อความถูกลบแล้ว

Saeide Hatamikhah

ยังไม่อ่าน,
20 ก.ค. 2558 02:29:5220/7/58
ถึง sel...@googlegroups.com

Kevin Brown

ยังไม่อ่าน,
31 ก.ค. 2558 15:43:5431/7/58
ถึง 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

ยังไม่อ่าน,
10 พ.ค. 2566 03:32:3910/5/66
ถึง select2
$(document).on('select2:open', () => {
document.querySelector('.select2-container--open .select2-search__field').focus();
});
ตอบทุกคน
ตอบกลับผู้สร้าง
ส่งต่อ
ข้อความใหม่ 0 รายการ