Dominik Wilga
Dominik Wilga

Reputation: 73

Select2 - filtering special characters

I have a problem with select2 plugin. When I use filter and type "mąka", it finds all the options with "mąka" and "maka" word. Is it possible to customize this script to find just the "mąka" word?

Preview here

Sorry for my english ;p

Thanks!

Upvotes: 2

Views: 2210

Answers (1)

Anurag
Anurag

Reputation: 101

From select2 site https://select2.github.io/examples.html#matcher

fiddle : https://jsfiddle.net/alaniex/c3Ls1uf3/1/

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)
  })
});

Upvotes: 3

Related Questions