TarekRaafat / autoComplete.js

Simple autocomplete pure vanilla Javascript library.
https://tarekraafat.github.io/autoComplete.js
Apache License 2.0
3.93k stars 236 forks source link

Programmatically fetching currently matched data #370

Open HawkOnPK opened 1 year ago

HawkOnPK commented 1 year ago

Hi,

It would be great if the data matched by the current input value could be programmtically read. I am working with an option where an item is selected under specific circumstances (e.g. being the last one available) without the input being focused and the auto-complete list shown - Normally we use the autocomplete list for a manual selection, but for specific cases (e.g. input scanner) it is instead used programmatically, but having the same underlying search/filtering/dataset. The internal method "findMatches" seems to do what i would imagine is necessary for receiving the correct set of matched results (disregarding the event handling).

Currently i am instead using a wrapper class and method which roughly does the same, using the autocomplete handlers data and search options (but e.g. missing filter options). As an alternative, using the "results" event did not work, since it seemed to trigger async so that: modifying the input > opening the autocomplete list > reading the matches from "results" event does not work, since "reading the matches" happens before the "results" event is triggered/handled.