Skip to content
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 · 16 comments
Closed

disable search on select boxes with multiple selection #4797

chlorophyllkid opened this issue Feb 16, 2017 · 16 comments

Comments

@chlorophyllkid
Copy link

@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
Copy link
Author

@chlorophyllkid 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
Copy link

@nflorentin nflorentin commented Mar 30, 2017

+1

1 similar comment
@Sartoric
Copy link

@Sartoric Sartoric commented Aug 2, 2017

+1

@3xcellent
Copy link

@3xcellent 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
Copy link
Contributor

@alexweissman alexweissman commented Oct 12, 2017

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

@alexweissman
Copy link
Contributor

@alexweissman alexweissman commented Oct 12, 2017

@thenitai
Copy link

@thenitai 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
Copy link

@emilas44 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
Copy link

@tabarjack 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
Copy link

@slbteam08 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
Copy link
Author

@chlorophyllkid 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
Copy link

@jjrr13 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

@Cessquill
Copy link

@Cessquill Cessquill commented Apr 24, 2019

Whilst I'm using the documented workaround on this, there are a few other gotchas I'm wrestling with...

  1. After loading, if you click on a label, the text box will be focused, as it has not yet disabled
  2. Once you've opened the select box (and hence disabled the search field), the label then does nothing (understandable, but annoying)

As mentioned, a proper option for search disable would be ideal - I'm using it for a user-defined set of options that will only ever be about a dozen, so typing not required. However, any ideas on fixing the above would be handy.

I've tried disabling on load to fix 1, but doesn't work.

@flash1nho
Copy link

@flash1nho flash1nho commented Jul 16, 2019

Hi! How to search local options when select2 ajax query is loaded this options?

изображение

@HankLloydRight
Copy link

@HankLloydRight HankLloydRight commented Feb 2, 2020

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');
});

The other workarounds did not work to totally disable the search on multi-select.
This one did. Thank you.

But an option 'disableSearch: true' would be a nice addition so we don't have to kludge around this.

@FridolinRozncvajk
Copy link

@FridolinRozncvajk FridolinRozncvajk commented Mar 5, 2020

$('select').on('select2:opening select2:closing', function( event ) {
	var $searchfield = $(this).parent().find('.select2-search__field');
	$searchfield.prop('disabled', true);
	$searchfield.attr('inputmode','none')
});

adding the inputmode part solved the ipad/iphone first click issue for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet