2015-05-06 02:19:05 +03:00
|
|
|
<section>
|
2015-05-31 22:10:51 +03:00
|
|
|
<h1 id="matcher">Customizing how results are matched</h1>
|
2015-05-06 02:19:05 +03:00
|
|
|
|
|
|
|
<p>
|
|
|
|
Unlike other dropdowns on this page, this one matches options only if
|
|
|
|
the term appears in the beginning of the string as opposed to anywhere:
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
This custom matcher uses a
|
|
|
|
<a href="options.html#compat-matcher">compatibility module</a> that is
|
|
|
|
only bundled in the
|
|
|
|
<a href="index.html#builds-full">full version of Select2</a>. You also
|
|
|
|
have the option of using a
|
|
|
|
<a href="options.html#matcher">more complex matcher</a>.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<div class="s2-example">
|
|
|
|
<p>
|
|
|
|
<select class="js-example-matcher-start js-states form-control"></select>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
2016-01-31 02:09:01 +03:00
|
|
|
{% highlight js linenos %}
|
2015-05-06 02:19:05 +03:00
|
|
|
function matchStart (term, text) {
|
|
|
|
if (text.toUpperCase().indexOf(term.toUpperCase()) == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$.fn.select2.amd.require(['select2/compat/matcher'], function (oldMatcher) {
|
|
|
|
$(".js-example-matcher-start").select2({
|
|
|
|
matcher: oldMatcher(matchStart)
|
|
|
|
})
|
|
|
|
});
|
2016-01-31 02:09:01 +03:00
|
|
|
{% endhighlight %}
|
2015-05-06 02:19:05 +03:00
|
|
|
</section>
|