Hello, I’m utilizing select2 and need to search listing from begin of string solely.
It is a WordPress web site url: https://florapal.org/a-test-home-page/
that is my js:
jQuery(doc).prepared(operate($)
$(".js-select2").select2(
placeholder: "Begin typing, or scroll to call",
allowClear: true,
matcher: operate(time period, textual content)
return textual content.toUpperCase().indexof(time period.toUpperCase())==0;
);
);
I’m getting “Uncaught TypeError: textual content.toUpperCase is just not a operate”
and I solely obtain “Looking…” beneath enter field – no outcomes.
Any assist a lot appreciated
I’m not acquainted with select2, however a fast have a look at the documentation signifies that the 2 arguments handed into matcher are objects.
e.g.
matcher: operate(params, knowledge)
// time period and textual content are object properties
const time period = params.time period
const textual content = knowledge.textual content
return textual content.toUpperCase().indexof(time period.toUpperCase())==0;
or with destructuring
matcher: operate(time period, textual content)
return textual content.toUpperCase().indexof(time period.toUpperCase())==0;