Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Bootstrap Typeahead matcher to case-insensitive

I need to set the matcher in the Twitter Bootstrap Typeahead plug-in to be case-insensitive. The Bootstrap docs specify that a function needs to be passed into the typeahead options, but doesn't specify what that function should be.

I'd be grateful if anyone could tell me how to do this.

Thanks in advance :)

like image 536
TheGuest Avatar asked May 30 '12 12:05

TheGuest


1 Answers

matcher is an option in the parameter for the typeahead function. From the documentation:

The method used to determine if a query matches an item. Accepts a single argument, the item against which to test the query. Access the current query with this.query. Return a boolean true if query is a match.

So, it would look something like this:

$('.typeahead').typeahead({
    matcher: function(item) {
        // Here, the item variable is the item to check for matching.
        // Use this.query to get the current query.
        // return true to signify that the item was matched.
        return true
    }
})

It also says in the documentation that the default behavior for this callback is a case insensitive matcher. So, your need should be met out of the box.

like image 146
ken Avatar answered Dec 17 '22 21:12

ken