focus event not working for select2 search text box?
I have a website that uses select2 and jquery 3.3.1. When opening a select2 dropdown, the search-textbox receives the focus so that it's easy to start searching. On mobile devices, this is annoying because it makes the virtual keyboard popup. A workaround I found is the following:
- $(document).ready(function () {
- window.select2typing = false;
- $(document).on("focus", ".select2-search__field", function () {
- if (window.select2typing == false) {
- $(this).blur();
- }
- });
- $(document).on("click", ".select2-search__field", function () {
- window.select2typing = true;
- $(this).focus();
- });
- $("select").on("select2:close", function () {
- window.select2typing = false;
- });
- });
This works fine in jquery 3.3.1 but when I upgraded tot 3.4.x it stopped working because it seems like the focus event is not working anymore. Is this a known problem? I downgraded tot 3.3.1 again for the time being...