Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hints corresponding with the text right from the start #50

Closed
quatzael opened this issue Mar 3, 2013 · 8 comments
Closed

Hints corresponding with the text right from the start #50

quatzael opened this issue Mar 3, 2013 · 8 comments

Comments

@quatzael
Copy link

quatzael commented Mar 3, 2013

Hi,

I like your jQuery-Autocomplete but I would find very useful if it was possible to add an option, in which hints would appear only if the first letters of the words match.
Now when I type first letter into the input, all the words that contain my letter will appear, but I need that only words starting at that letter would appear.

For example:
I am starting typing 'ne'.. and Maine would appear just because it contains 'ne' but I need that only Nebraska, New Hampshire, New Jersey, New Mexico and so on would appear..

I hope you get me.

Is it possible to add this little amendment??
I would really appreciate this.

Thanks.

@tkirda
Copy link
Member

tkirda commented Mar 3, 2013

You can provide your own function that determines what should be included. See lookupFilter function in the source and documentation. In your case it should be:

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

@tkirda tkirda closed this as completed Mar 3, 2013
@quatzael
Copy link
Author

quatzael commented Mar 3, 2013

Thanks, that is exactly what I meant.

@quatzael
Copy link
Author

Hi, I'm here again!
Is it also possible for the hints to have only the starting letters highlighted?
Example:
I am starting to type ROVER and when I type the first letter R, both the first and the last R is highlighted so it is like:
R O V E R. But I need only the first letter to be highlighted so it would be like: R O V E R.
Thanks.

@tkirda
Copy link
Member

tkirda commented Apr 26, 2013

Hi, you will need to provide your own formatResult function. I slightly modified the default, this should do the job:

formatResult: function (suggestion, currentValue) {
    var reEscape = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'].join('|\\') + ')', 'g'),
        pattern = '^(' + currentValue.replace(reEscape, '\\$1') + ')';

    return suggestion.value.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
}

@albanR
Copy link

albanR commented Aug 22, 2013

thanks @tkirda for the time you spent on answering that question, exactly what I needed.

@zaibkhan
Copy link

zaibkhan commented Jun 2, 2014

Hi,

How i can sort the result. I like to sort my suggestions that exact match letter come first and rest of the result after that. for example

when i type app the first result should show app, apple, application and and rest like other matching like web application etc.

Please help

@tkirda
Copy link
Member

tkirda commented Jun 2, 2014

If results are coming from the server, then sorting is server responsibility. If client side, then you will need to alter the source in the getSuggestionsLocal function and sort data before returning.

@zaibkhan
Copy link

zaibkhan commented Jun 2, 2014

thanks i fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants