Alihuseyn
Alihuseyn

Reputation: 158

JQuery Autocomplete search both to letters

I implemented autocomplete which fetch all data with ajax post from database and add them to autocomplete as item. which is shown below

jQuery.ajax({
     url: "--url--",
     dataType: 'jsonp',
     success: function(data){
        jQuery("#location_finder").autocomplete({
            source: function( request, response ) {
                var lookup = jQuery.ui.autocomplete.escapeRegex( request.term );
                var matcher = new RegExp( "^" + lookup, "i" );
                response( jQuery.grep(data, function(item){
                     return matcher.test(item);
                }));
            }
        });
    },
});

The data after post come as :

data = ['Berti','Simon','Çarli','Cherpa'];

While doing typing in input field for letter "C" only "Cherpa" shown but I try to show "Çarli" also to user. How can I handle it and give option to user both letter "C" and "Ç"? Thanks in advance.

Upvotes: 2

Views: 118

Answers (1)

Tim B
Tim B

Reputation: 1983

You can try :

var lookup = jQuery.ui.autocomplete.escapeRegex( request.term );
if(lookup.indexOf('C') != -1 || lookup.indexOf('Ç') != -1) {
    lookup.replace("C", "(C|Ç)");
    lookup.replace("Ç", "(C|Ç)")
}
var matcher = new RegExp( "^" + lookup, "i" );

Upvotes: 1

Related Questions