New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable search on select boxes with multiple selection #4797

Closed
chlorophyllkid opened this Issue Feb 16, 2017 · 12 comments

Comments

Projects
None yet
10 participants
@chlorophyllkid

chlorophyllkid commented Feb 16, 2017

Hi everyone,

as the title indicates I'm looking for a possibility to disable the search on selects with multiple selection.

I already know there is:
minimumResultsForSearch: Infinity

And it works fine on selects with single selection, but doesn't seem to have any effect on select boxes with multiple selection.

Oh, and I'm currently using select2 4.0.3..

Here is a fiddle http://jsfiddle.net/jEADR/3608/

thanks in advance :)

@chlorophyllkid

This comment has been minimized.

chlorophyllkid commented Feb 16, 2017

My current workaround is this:

$('select').on('select2:opening select2:closing', function( event ) {
    var $searchfield = $( '#'+event.target.id ).parent().find('.select2-search__field');
    $searchfield.prop('disabled', true);
});
@nflorentin

This comment has been minimized.

nflorentin commented Mar 30, 2017

+1

1 similar comment
@Sartoric

This comment has been minimized.

Sartoric commented Aug 2, 2017

+1

@3xcellent

This comment has been minimized.

3xcellent commented Aug 7, 2017

Also hitting this. Would really like to have the search option disabled for multiselects with finite options. My work-around (not very elegant):

setTimeout(function() {
$('input[type=search]').attr('disabled', 'disabled');
});

@alexweissman

This comment has been minimized.

Contributor

alexweissman commented Oct 12, 2017

@chlorophyllkid your solution seems to work well, so I am adding it to the documentation.

@alexweissman

This comment has been minimized.

Contributor

alexweissman commented Oct 12, 2017

@thenitai

This comment has been minimized.

thenitai commented Feb 12, 2018

I somehow couldn't get the proposed solution to work. However, this one works for me every time:

$('#selectid').on('select2:open select2:opening select2:closing', function( event ) {
  $('.select2-results').css('display', 'none');
});
@emilas44

This comment has been minimized.

emilas44 commented May 1, 2018

Is it possible to completely disable user input. I still can type in the select box. I want to disable it.

@tabarjack

This comment has been minimized.

tabarjack commented Jun 28, 2018

For those who might wind up here from a google search like I did:

I used this and it works even on a refresh. Note that I haven't tested with sending values to the server because it's only for an in-page filter (and that works so no reason sending to server wouldn't, mentioning just in case).

obj.on('select2:opening', function(e){ $('.select2-search__field').prop(readonly, true); }

@slbteam08

This comment has been minimized.

slbteam08 commented Sep 18, 2018

My current workaround is this:

$('select').on('select2:opening select2:closing', function( event ) {
    var $searchfield = $( '#'+event.target.id ).parent().find('.select2-search__field');
    $searchfield.prop('disabled', true);
});

This documented solution works only from the second click on iPad. On the first click before the input is disabled, the iPad keyboard occurs already. Are there any events that can be used before the first click?

@chlorophyllkid

This comment has been minimized.

chlorophyllkid commented Sep 18, 2018

I guess at this point workarounds should not be the proper solution to this problem anymore.
It would be far easier to just have a real option like disableSearch: true which handles this use case.

@jjrr13

This comment has been minimized.

jjrr13 commented Oct 2, 2018

Alguien me puede ayudar con mi problema? sucede que mi select2 no busca y se queda en la parte inferior con Serching, y no pasa de ese punto, quizas alguien me puede indicar las posibles razones.

Muchas gracias de ante mano

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment