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
In my application, it does not ever focus the search text box. I am using version 4.0.13, but I think it should.
I also noticed, on the Appearance | Select2 - The jQuery replacement for select boxes page, the behaviour is not consistent:
- in almost all dropdowns, it focus the search text box
- except one, the Label section dropdown, which for a moment focus there, but then bounces back out of it.