Help - After upgradde from 3.52 to 4.01, matcher does not work the same

187 views
Skip to first unread message

Don Proshetsky

unread,
Dec 8, 2015, 11:40:12 AM12/8/15
to select2
I migrated from select2 3.52 to 4.01 but I do find the documentation to be poor., sorry. Could anyone tell me what option(s) should be used to make select2 search function filter words that just begin with search term and not if it is contained in the middle. Please don't tell me to look at the example in the documentation as I have, tried to make it work and have been unsuccessful.

My JS code is:

      $("#lstOrigin_home").select2({
         dropdownAutoWidth:false,
         allowClear:true,
         width:"237px",
         oldMatcher: function(term, text) { return text.toUpperCase().indexOf(term.toUpperCase())==0; }
      });

I need the oldMatcher: to work as before.

Thanks / Don

Kevin Brown

unread,
Dec 8, 2015, 5:46:15 PM12/8/15
to select2
I noticed that the related GitHub ticket has been closed, so I'm assuming you've resolved this on your own.

I'll point back to this Stack Overflow answer as a working example of using the `oldMatcher` compatibility function (note: it's not an option) with newer versions of Select2: http://stackoverflow.com/q/31571864/359284#31575725

--
You received this message because you are subscribed to the Google Groups "select2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to select2+u...@googlegroups.com.
To post to this group, send email to sel...@googlegroups.com.
Visit this group at http://groups.google.com/group/select2.
For more options, visit https://groups.google.com/d/optout.

Don Proshetsky

unread,
Dec 8, 2015, 6:07:41 PM12/8/15
to select2
I tried this but it did not work. I this case, there were no JS errors but the <select> did not become a select2 object but instead remained as an regular HTML select. I know a few others have asked this and not received a resolution so I think the only resolution is to stay with 3.5.3

Kevin Brown

unread,
Dec 9, 2015, 4:08:30 PM12/9/15
to select2
Here's a jsbin that combines the Stack Overflow answer with the code you provided in the original message.


Note that you need to use the full version of Select2 and you need to use the original `matcher` option while wrapping your old matching function with the `oldMatcher` call.

Select2 should only fail to initialize if either no instances are found or if there was an error during initialization. So make sure that your selector actually matches the elements you are looking for, and set `debug: true` during initialization if you get any JS errors.

--
Reply all
Reply to author
Forward
0 new messages