I had this issue with Jquery v3.6 .Its fine on v3.7
$(document).on(āselect2:openā, () => {
document.querySelector(ā.select2-containerāopen .select2-search__fieldā).focus();
});
it works, but if using select2 more than two :
$(ā.select2ā).click(function(){
document.querySelector(ā.select2-containerāopen .select2-search__fieldā).focus();
});
A fix that worked for me and perhaps others. I was having this issue when I had my HTML set up with the select
inside the label
(as is shown in the documentation), but when I moved the select
outside the label
the search maintained focus.
Original:
<label for="someId">Label:
<select id="someId">...</select>
</label>
Working HTML:
<label for="someId">Label:</label>
<select id="someId">...</select>
Iām not sure if this will help anyone else, but it was the solution for me