Option to disable or hide search
Is there a way to disabled search inside select?
See #414
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...
I would love to have this option.
implemented in master, set minimumResultsForSearch to a negative value.
As stated in https://github.com/ivaynberg/select2/issues/189, hiding the input alone really doesnt solve the problems you may encounter
I must say that seems a bit of a cryptic way to do it, but okay.
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.
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.
For current version , you should set to a enough positive number, like 99999, to disable search box.
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
});

@almogdesign There's two issues there, neither of which Select2 can reasonably control
- You're trying to disable search on a multiple select, but the
minimumResultsForSearchoption 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. - 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 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
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.
Is it possible to have attr to control this option (show/hide search for some of selects)?
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);
});`
how do I remove all options from a select2 control?