From c4e681f675e4ebe5ef58cfc393ca6012c02b7a52 Mon Sep 17 00:00:00 2001 From: Igor Vaynberg Date: Tue, 17 Jul 2012 20:07:58 +0300 Subject: [PATCH] added an example of a custom matcher that uses the option tag --- select2-latest.html | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/select2-latest.html b/select2-latest.html index db8776dc..623a37f9 100755 --- a/select2-latest.html +++ b/select2-latest.html @@ -778,6 +778,16 @@ $("#e16_disable").click(function() { $("#e16,#e16_2").select2("disable"); }); $(document).ready(function () { $("#e17").select2({ matcher: function(term, text) { return text.toUpperCase().indexOf(term.toUpperCase())==0; } +}); +// +$("#e17_2").select2({ + matcher: function(term, text, opt) { + return text.toUpperCase().indexOf(term.toUpperCase())>=0 + || opt.attr("alt").toUpperCase().indexOf(term.toUpperCase())>=0; + } }); }); @@ -785,6 +795,8 @@ $("#e17").select2({

Custom Matcher

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


+

The dropdown below matches on custom attributes of the option tag. For example, the `blue` option can be matched by entering either `blue` or `cyan`.

+

Example Code