select2 icon indicating copy to clipboard operation
select2 copied to clipboard

Option to disable or hide search

Open buste opened this issue 14 years ago • 16 comments

Is there a way to disabled search inside select?

buste avatar Oct 11 '12 08:10 buste

See #414

dejan avatar Oct 11 '12 18:10 dejan

High value of minimumResultsForSearch only hides searchbox in opened select. But if we type some letter while select is closed and focused - search will pop up, no matter how high is minimumResultsForSearch and how many actual options in select we have. So we need more convinient way to disable searching...

andreyvolokitin avatar Dec 18 '12 10:12 andreyvolokitin

I would love to have this option.

RobertCordes avatar Feb 13 '13 10:02 RobertCordes

implemented in master, set minimumResultsForSearch to a negative value.

ivaynberg avatar Feb 14 '13 06:02 ivaynberg

As stated in https://github.com/ivaynberg/select2/issues/189, hiding the input alone really doesnt solve the problems you may encounter

blowsie avatar Oct 14 '13 11:10 blowsie

I must say that seems a bit of a cryptic way to do it, but okay.

Pushplaybang avatar Apr 01 '14 13:04 Pushplaybang

Would be helpful to mention this in the docs. Too maintain consistent styling I use select2 for all my selects. A select with two or three options doesn't need a search field.

greghouston avatar Apr 11 '14 06:04 greghouston

It seems like if I choose an option then return to change it, the searchbox would come back.

I did a little debugging and it seems like the second time it opens the dropdown minimumResultsForSearch would be set to 0 automagically for some reason.

tyteen4a03 avatar Nov 27 '14 05:11 tyteen4a03

For current version , you should set to a enough positive number, like 99999, to disable search box.

maple-leaf avatar Feb 27 '15 03:02 maple-leaf

None of this seems to work with the latest version 4.0. I have a multiple select box and I'm still getting the search icon might be a bug. I tried different settings with minimumResultsForSearch

<select id="observationSelection" style="width: 75%" multiple="multiple" data-parsley-group="step3">
                                                        <optgroup label="Irrigación">
                                                            <option>aplicar riego</option>
                                                            <option>no aplicar riego</option>
                                                            <option>aumentar frecuencia del periodo de riego</option>
                                                            <option>disminuir periodo de riego</option>
                                                            <option>reducir caudal de agua</option>
                                                            <option>reformar boquilla</option>
                                                            <option>reformar muros</option>
                                                            <option>limpieza de drenaje</option>
                                                            <option>construcción de drenaje</option>
                                                        </optgroup>
                                                        <optgroup label="Sigatoka">
                                                            <option>hacer aplicación</option>
                                                            <option>hacer deshoje</option>
                                                            <option>hacer laminado y biselado</option>
                                                            <option>monitoreo</option>
                                                        </optgroup>

                                                    </select> 
 $("#observationSelection").select2({
        minimumResultsForSearch: -1
    });

screen shot 2015-05-10 at 11 43 22 am

isAlmogK avatar May 10 '15 08:05 isAlmogK

@almogdesign There's two issues there, neither of which Select2 can reasonably control

  1. You're trying to disable search on a multiple select, but the minimumResultsForSearch option only has control over single selects. This is because the search for a multiple select is built into the design, while the search for a single select is built into the dropdown.
  2. The search icon doesn't exist in Select2 4.0, which you should be able to confirm by the fact that Select2 doesn't include a search icon at all. This might be the result of your browser, or other styles which just happen to be conflicting with Select2 because it is a search box (<input type="search" />).

kevin-brown avatar May 10 '15 16:05 kevin-brown

@kevin-brown thanks, yea I saw that there is no search icon and checked the docs. Your right one of the CSS stylesheets was still loading. Thanks for the help

isAlmogK avatar May 10 '15 18:05 isAlmogK

I edited the select2.min.js file to set the select-2__search input field that's generated to readonly="true" since the documented setting wouldn't work for multiple select fields.

capcom-r avatar Apr 26 '17 00:04 capcom-r

Is it possible to have attr to control this option (show/hide search for some of selects)?

selcet avatar Jan 09 '18 18:01 selcet

for disable or hide search , i use this code:

            `$('#select').focus(function( event )
            {
                var $searchfield = $( '#'+event.target.id ).parent().find('.select2-search__field');
                $searchfield.prop('disabled', true);
            });
            
            $('#select').click(function( event )
            {
                var $searchfield = $( '#'+event.target.id ).parent().find('.select2-search__field');
                $searchfield.prop('disabled', true);
            });
            
            $('#select').change(function( event )
            {
                var $searchfield = $( '#'+event.target.id ).parent().find('.select2-search__field');
                $searchfield.prop('disabled', true);
            });`

mokhtasatxyz avatar Jul 21 '18 15:07 mokhtasatxyz

how do I remove all options from a select2 control?

damianvadone avatar Oct 11 '20 04:10 damianvadone