user2224150
user2224150

Reputation: 95

jquery select2 plugin how to get only the result 'myString%'

i'm using the jquery-select2 plugin but i'm wondering how can i get only results that begins with the typed keyword ( like 'myString%')

Upvotes: 3

Views: 3939

Answers (1)

Fabrício Matté
Fabrício Matté

Reputation: 70169

The documentation actually provides an example for that:

$("select").select2({
    matcher: function(term, text) {
        return text.toUpperCase().indexOf(term.toUpperCase())==0;
    }
});

The above matcher is case-insensitive, for case-sensitive remove both .toUpperCase() calls.

Upvotes: 11

Related Questions