V
V
Vasilpetrovuch22021-01-26 13:16:43
JavaScript
Vasilpetrovuch2, 2021-01-26 13:16:43

How to make a filter for the search field in the select2 library?

How can I set/trim the search string in select2?

Example - https://jsfiddle.net/afLw1vps/
There is a list with cities. It is necessary that the search does not read the entire line of text, but only the text that is before the bracket. How can this be done?

Because now it turns out that if we are looking for "Moscow", then we need to enter an almost full name, since information about the region to which a particular city belongs is mentioned in brackets

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alvvi, 2021-01-26
@alvvi

The search function can be customized: https://select2.org/searching
I think writing a function that excludes the part outside the bracket from the string is not difficult.
For reference, here is https://github.com/select2/select2/blob/develop/sr... here you can find the default matcher function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question