0👍
✅
The filtering is being processed by Select2
. You can set this function I’ve borrowed from the official documentation and modified in order to achieve your goal.
$('.reagent_selector').select2({
width: '100%',
matcher: function(params, data) {
if(params.term.trim() === '')
return data;
if(typeof data.text === 'undefined')
return null;
if(data.text.toLowerCase().match('\\b' + params.term.toLowerCase()))
return data;
return null;
}
});
I changed the search function to match only the options that contain at least one word starting with the input text.
The \\b
up there is a regex anchor used to match “word boundary”. In this case, I’m forcing the input text to be at the beginning of a word, not in the middle.
Source:stackexchange.com