How to use matcher in select2.js v.4.0.0 +?

If I understand correctly, the correct use of the match before v4.0.0 was:

$('#myselect').select2({ ... matcher: function(term, text) { // return true if matches, false if not } }) 

With 4.0.2 this will not work - AFAICT has only one matcher parameter, which is an object. I could use the same function signature and wrap it with oldWrapper , but I would like to avoid this ... I could not find any example or documents. So how do I use the new helper? Or at least what is a function signature?

+5
source share
1 answer

Found: https://github.com/select2/select2/blob/master/src/js/select2/defaults.js (search for function matcher ).

Basically, the function signature:

 matcher: function (params, data) { // should return: // - null if no matches were found // - `data` if data.text matches params.term } 

My problem, however, was that β€œtext” is the solid name of the field β€” I, of course, used something else. Hope this helps someone.

+9
source

Source: https://habr.com/ru/post/1247012/


All Articles