Search code examples
jqueryjquery-select2

select2 keyboard issue on mobile


I have an issue with select2, when it is being used on mobile devices. On click, the virtual keyboard is shown. I tried using something like

$('select').select2({
  shouldFocusInput: function (instance) {
        // Attempt to detect touch devices
        var supportsTouchEvents = (('ontouchstart' in window) ||
                                   (navigator.msMaxTouchPoints > 0));

        // Only devices which support touch events should be special cased
        if (!supportsTouchEvents) {
            return true;
        }

        // Never focus the input if search is disabled
        if (instance.opts.minimumResultsForSearch < 0) {
            return false;
        }

        return true;
    }
});

with no success. Even if I try to simply use

shouldFocusInput: false

the search text keeps getting focused.


Solution

  • have you tried

    minimumResultsForSearch = -1
    

    post of issue: https://github.com/ivaynberg/select2/issues/1541