autoComplete.js icon indicating copy to clipboard operation
autoComplete.js copied to clipboard

API Call to select an resultItem is not working

Open Erseni opened this issue 2 years ago • 3 comments

The following api call autoCompleteJS.select(0); is throwing a TypeError Uncaught TypeError: Cannot set properties of undefined (setting 'event')

To reproduce just enter the api call at the end of the official codepen example: https://codepen.io/tarekraafat/pen/rQopdW

Erseni avatar Jul 08 '22 07:07 Erseni

The following api call autoCompleteJS.select(0); is throwing a TypeError Uncaught TypeError: Cannot set properties of undefined (setting 'event')

To reproduce just enter the api call at the end of the official codepen example: https://codepen.io/tarekraafat/pen/rQopdW

Got the same Issue

maksimbykov avatar Aug 23 '22 13:08 maksimbykov

added PR https://github.com/TarekRaafat/autoComplete.js/pull/369

maksimbykov avatar Sep 01 '22 09:09 maksimbykov

If you place autoCompleteJS.select(0) in the results event, it fires without error. autoCompleteJS.input.addEventListener("results", function (event) { console.log(event.detail); autoCompleteJS.select(0) });

Type something and item with index 0 is automatically selected.

I guess if autoCompleteJS.select(0) is run before, the Init event may not be finished yet which throws error. Explained also in in PR #369

AndrewElans avatar Apr 29 '23 06:04 AndrewElans