Question

I am using below plugin to create autocomplete feature:

https://github.com/devbridge/jQuery-Autocomplete

below is their live demo:

http://www.devbridge.com/sourcery/components/jquery-autocomplete/#jquery-autocomplete

now the problem is, I'd like to filter the result and only show letter match start with first letter.

for example, if I typed into 'a', only countries start with 'a' should appear.

I checked this plugin's library, I saw there is a lookupFilter function there, but don't know how to use it.

would anyone who had used this library before kindly give some pointers?

I'd like to use this plugin instead of jQuery UI, as it is light weighted.

Was it helpful?

Solution

I checked lookupFilter in their library and below is the code:

lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
    return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1;
},

Here they are returning the value bascially if it is present in the results.

-1 means the letter a is not found, so they're returning the value at any occurrence.

So just tune it as:

lookupFilter: function (suggestion, originalQuery, queryLowerCase) {
    return suggestion.value.toLowerCase().indexOf(queryLowerCase) === 0;
},

Exactly at 0th index.

This will return the results with a as first occurance.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top