Using select2 when searching for list matches only from the beginning of a string – JavaScript – SitePoint Forums

1675137033 cf11b3ed553d6c359d3dcc08377cc4b121fe8bf0


Hi I am using select2 and want to search the list only from the beginning of the string.
This is the URL of the WordPress site:
this is my js:

jQuery(document).ready(function($) {
   placeholder: "Start typing, or scroll to name",
   allowClear: true,   
   matcher: function(term, text) {
     return text.toUpperCase().indexof(term.toUpperCase())==0;

I get the message “Uncaught TypeError: text.toUpperCase is not a function”
I only see “Searching…” below the input box – no results.
Any help would be greatly appreciated

I’m not familiar with select2, but a quick look at the documentation shows that the two arguments passed to the matcher are objects.

for example

matcher: function(params, data) {
  // term and text are object properties
  const term = params.term
  const text = data.text

  return text.toUpperCase().indexof(term.toUpperCase())==0;

or with destruction

matcher: function({term, text}) {
  return text.toUpperCase().indexof(term.toUpperCase())==0;


Source link

What do you think?

Leave a Reply

GIPHY App Key not set. Please check settings

    1675124938 inn social default

    State Farm Mutual Automobile Insurance Company – InsuranceNewsNet


    Talithia Williams Kicks Spring College Forum Series Feb 7