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

Not working when input targetted is "display: none" #367

Closed huiyang closed 2 years ago

huiyang commented 2 years ago

System Information

Describe the bug autocomplete.js instant not working when it is display: none, it work after display: none is removed.

To Reproduce Steps to reproduce the behavior:

  1. Use the following config
  2. Create a input text field with ID "search-input"
  3. Add the following css
  4. #search-input {
    display: none;
    }
  5. When user type on the text field, console should output the query typed, but it don't, nothing happened

Expected behavior Autocomplete instant should work, when user type on the text field, console should output the query typed.

Configuration used

{
        selector: "#search-input",
        debounce: 500, // Milliseconds value

        //placeHolder: "Search for Food...",
        data: {
            src: async (query) => {
                console.log('q', query)
                try {
                    // Fetch Data from external Source
                    const source = await fetch(autoCompleteUrl + '?q=' + query);
                    // Data should be an array of `Objects` or `Strings`
                    const data = await source.json();
                    return data.records.data;
                } catch (error) {
                    return error;
                }
            },
            // Data source 'Object' key to be searched
            keys: ["name"]
        }
}
huiyang commented 2 years ago

Sorry my mistake. It is actually caused by 2 element with same ID.

BTW, hope that the selector can select multiple elements when class selector is applied.