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

1

5

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

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

With 4.0.2 this doesn't work - AFAICT there is only one parameter to matcher, which is an object. I could use the same function signature and wrap it on oldWrapper, but I would like to avoid that... I was unable to find any example or docs. So, how do I use the new matcher? Or at least, what is the function signature?

Vagrom answered 13/4, 2016 at 7:29 Comment(0)
V
9

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

Basically, the function signature is:

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

My problem however was connected to the fact that "text" is a hardcoded field name - I was of course using something else. Hope it helps someone.

Vagrom answered 13/4, 2016 at 8:54 Comment(1)
Thanks man! it just helped me :) thank you for replying with this!Audacity

© 2022 - 2024 — McMap. All rights reserved.