devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.56k stars 1.66k forks source link

No item selected on ExactMatch #841

Closed noskill24 closed 1 year ago

noskill24 commented 2 years ago

onSelect-event doesn't firing if array of suggestions contains similar values:

var countries = [
    "Andorra",
    "Andorra 1",
    "Andorra 12",
    "Andorra 123",
[;

If I type "Andorra 123" (using keyboard, not select) - onSelect event will fire because there is ONE exact match! If I type for example "Andorra" - onSelect event will not fire because there are FOUR matches!

But there is STILL ONE exact match - "Andorra" from four total matches (three other are not exact)!

This bug happens because isExactMatch-function checks exact match when one and only one match is found.

  isExactMatch: function (query) {
    var suggestions = this.suggestions;
    return (suggestions.length === 1 && suggestions[0].value.toLowerCase() === query.toLowerCase());
  },
tkirda commented 2 years ago

Yes, that is by design. If there are more matches, allow user to type more or they should select an option.

noskill24 commented 2 years ago

If user just types"Andorra", why it is not equal to select "Andora"? I think it is poor design. User selected this value by typing. Ok, how can I detect Exact Match in this case?

svennd commented 1 year ago

If user just types"Andorra", why it is not equal to select "Andora"? I think it is poor design. User selected this value by typing. Ok, how can I detect Exact Match in this case?

I think you should be able to figure out why ...

The user can just press enter to select it. Else you would not be able to type "Andorra 12", it would jump directory to "Andorra".

You could (ab)use onSearchComplete for this :

        onSearchComplete: function (query, suggestion) { 

            if(query == suggestion[0].value)
            {
                console.log("we should select this one");
            }
        },

Most certainly there are more elegant solutions possible.

tkirda commented 1 year ago

That is by design.