79673636

Date: 2025-06-20 15:30:28
Score: 3
Natty:
Report link

I have the same problem. In some cases I was unable to focus in search input of opened select2.

After some debugging I found that jQuery 3.7.1 tries to fix some unexpected behaviour of focusin/focusout event. Here is code with that fix. If you curious, and also brave enough, check it.

That code captures focus related events on #document a do some magic with them, which unfortunately leads to select2 won't work.

It could be fixed like this:

/**
 * Call this in your document.ready function
 */
function fixSelect2SearchInputWontFocus() {

    // on select2:open there is fresh .select2-container
    $(window).on('select2:open', () => {

         // stop propagation of events up to #document
         $('.select2-container').on('focus blur focusin focusout', e => {
             e.preventDefault();
             e.stopPropagation();
         });

         // off event is not needed, container is removed on close
    });

}

Reasons:
  • Blacklisted phrase (1): I have the same problem
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): I have the same problem
  • Low reputation (0.5):
Posted by: Vladimír Mlázovský