pawelczak / EasyAutocomplete

JQuery autocomplete plugin
http://easyautocomplete.com
MIT License
729 stars 243 forks source link

AutoComplete based only on first letter(s)? #172

Open GioLogist opened 8 years ago

GioLogist commented 8 years ago

Is it possible to make it only autocomplete based only on the first letter(s) typed?

IE: Right now it searches based on '%A%' instead of 'A%', so if I type "A" i get both "Ants" and "Panda", my aim is to only get "Ants".

pawelczak commented 8 years ago

I've added modifications, that allows you to change match method. I've prepared jsfiddle with example: https://jsfiddle.net/s42jj5p5/

I didn't released code, so you need to use plugin files from "dist" folder https://github.com/pawelczak/EasyAutocomplete/tree/master/dist

ShantaramTupe commented 8 years ago

hello pawelczak sir, I didn't got this example please elaborate .. https://jsfiddle.net/s42jj5p5/ I have same situation , and want to search as @GioLogist asked ... thank you

launay12u commented 8 years ago

It may be too late but I found a issue : On line 654 of js change : value.search(phrase) > -1

to

value.lastIndexOf(phrase,0) === 0

rcatwr commented 8 years ago

Changing line 46 to: if (a === b){ return 1; } and 63 to: if (element.search(phrase) === 1)

in jquery.easy-autocomplete.js appears to search as per @GioLogist requested.

bonucci commented 7 years ago

@rcatwr i tried but isnt working, if you use for example you will notice that isnt bring the data that starts with "FR", im searching by "label", and the final result im looking for is "FR Ryanair" , list example: http://www.json-generator.com/api/json/get/cdLxcejibm?indent=2

rcatwr commented 7 years ago

@bonucci -- leave 45 as:

if (a < b) {
         return -1;
    }
    if (a > b) {
    return 1;
    } 

try changing line 65 to:

if (element.search(phrase) === 0) {
                            return true;
                        } else {
                            return false;
                        }
ilgityildirim commented 7 years ago

In case if someone would need this for later while initiating easyAutoComplete, pass this as an option;

list: {
    match: {
        method: function(element, phrase) {
            return (element.lastIndexOf(phrase, 0) === 0);
         }
    }
}

And you don't need to edit any source code as this is a bad practice and there is a solution for this.