Custom matchers in Select2-4..0.0-beta.3

523 views
Skip to first unread message

bee...@gmail.com

unread,
Jan 30, 2015, 7:07:28 AM1/30/15
to sel...@googlegroups.com
I wonder if anyone might be able to point me at a more complete example of using custom matchers in the Beta of select2 than the one on the examples page at https://select2.github.io/examples.html as I seem to be missing something in my code.

I'm loading the Javascript in my page thus:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="/pubs/javascript/Standard/optional/select2.amd.js"></script>
<script src="/pubs/javascript/combined.js"></script> // my site JS

Then wrapping my selector with:

$.select2.amd.require(['select2/compat/matcher'], function (oldMatcher)
{
var t = $('#townselect').select2(
{
matcher: oldMatcher(matchStart),
placeholderOption:'first'
});
});
function matchStart (term, text)
{
if (text.toUpperCase().indexOf(term.toUpperCase()) === 0)
{
return(true);
}
return(false);
}

But when I try to run the code I get the following errors:
11:45:02.034 ReferenceError: define is not defined select2.amd.js:1:0
11:45:04.041 TypeError: $.select2 is undefined combined.js:1458:2

trying the same thing using select2.full.js, I get:
11:58:04.749 TypeError: $.select2 is undefined combined.js:1458:2

I also tried changing "$.select2.amd.require" to "$.select2.full.require" and even "$.select2.require" in case this was necessary, but with no change.

I'm obviously missing something that should be obvious to me, but even studying the source of the examples page hasn't helped.

I'd be grateful for any pointers to get me in the right direction.

bee...@gmail.com

unread,
Feb 22, 2015, 8:02:34 AM2/22/15
to sel...@googlegroups.com, bee...@gmail.com
In the absence of any replies to this, I'll reply myself with the solution I finally found, in the hope it'll help someone in the future.

Where the documentation says:

> $.select2.amd.require(['select2/compat/matcher'], function (oldMatcher)

it isn't quite correct. It should be (in my case)

> $('#townselect').select2.amd.require(['select2/compat/matcher'], function (oldMatcher)

Whether this is an error in the documentation or just me failing to spot something that is obvious to everybody else, I'm not sure.

Kevin Brown

unread,
Feb 22, 2015, 3:06:55 PM2/22/15
to sel...@googlegroups.com
This appears to be an error in the documentation, the line should actually read

> $.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher)

As the AMD methods are attached to the $.fn.select2 object.


--
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.

Reply all
Reply to author
Forward
0 new messages