jQuery Autocomplete: How To Search From The Start

I came across a problem using the autocomplete function in jQuery.

I use a search for countries, and I want the result to start with the letter I fill in the textbox, but instead, I got all the results containing the user input.

I spent some time searching for an answer, but I couldn’t find anything, so I started to look in the source (in my case: jquery-ui-1.8.9-custom.min.js).

In the autocomplete function, I ended up changing this:

filter:function(a,b){var f=new RegExp(d.ui.autocomplete.escapeRegex(b),"i");

to this:

filter:function(a,b){var f=new RegExp("^" + d.ui.autocomplete.escapeRegex(b),"i");

Now it finally works properly.

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.