title: Search taxonomy:
category: docs
process:
twig: true
The appearance and behavior of the search control can be easily customized with Select2.
You may customize the way that Select2 matches search terms by passing a callback to the matcher
option. This example matches results only if the term appears in the beginning of the string as opposed to anywhere:
This custom matcher uses a compatibility module that is only bundled in the full version of Select2. You also have the option of using a more complex matcher.
You may limit the maximum length of search terms by using the maximumInputLength
option:
$('select').select2({
maximumInputLength: 20 // only allow terms up to 20 characters long
});
The minimumResultsForSearch
option determines the minimum number of results required in the initial population of the dropdown to display the search box.
This option is useful for cases where local data is used with a small result set, and the search box would simply be a waste of screen real estate. Set this value to -1 to permanently hide the search box.
$('select').select2({
minimumResultsForSearch: 20 // at least 20 results must be displayed
});
Select2 allows you to hide the search box depending on the number of options which are displayed. In this example, we use the value Infinity
to tell Select2 to never display the search box.