jQuery-Autocomplete icon indicating copy to clipboard operation
jQuery-Autocomplete copied to clipboard

No item selected on ExactMatch

Open noskill24 opened this issue 2 years ago • 1 comments

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());
  },

noskill24 avatar Sep 19 '22 19:09 noskill24

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

tkirda avatar Sep 22 '22 18:09 tkirda

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?

noskill24 avatar Oct 17 '22 14:10 noskill24

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.

svennd avatar Dec 28 '22 15:12 svennd

That is by design.

tkirda avatar Dec 28 '22 23:12 tkirda