Question

I am using this parameter to make my bootstrap typeahead search in insensitive case mode.

matcher: function(item) {
    return true
}

I works for accents like typing "e" searches also é,è,ë,ê etc... But does not work for upper an lower case => typing "g" doesn't look for "G"...

Is there an other parameter?

Was it helpful?

Solution

Ok here is what i did using Paul's solution :

             matcher: function(item) {
                if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
                    return true;
                }
                if (item.toUpperCase().indexOf(this.query.trim().toUpperCase()) != -1) {
                    return true;
                }
                var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&');
                query = query.replace(/a/ig, '[a\341\301\340\300\342\302\344\304]');
                query = query.replace(/e/ig, '[e\351\311\350\310\352\312\353\313]');
                query = query.replace(/i/ig, '[i\355\315\354\314\356\316\357\317]');
                query = query.replace(/o/ig, '[o\363\323\362\322\364\324\366\326]');
                query = query.replace(/u/ig, '[u\372\332\371\331\373\333\374\334]');
                query = query.replace(/c/ig, '[c\347\307]');
                if(item.toLowerCase().match(query.toLowerCase())){
                    return true;
                }
            }

With this, you have a real insensitive case. I putted the main special characters. You may want to add extra characters for the match.

OTHER TIPS

Hi i had the same problem and solved my problem this way:

    matcher: function (item) {
                if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
                    return true;
                }
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top