TarekRaafat / autoComplete.js

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

Unhandled Promise Rejection: TypeError: el is not an Object #298

Closed SamusAranX closed 2 years ago

SamusAranX commented 2 years ago

I'm using Safari on macOS Monterey.

This is how I tried initializing the autocompletion thing:

var ac;
window.addEventListener("load", function () {
    let config = {
        selector: ".autocomplete",
        wrapper: true,
        data: {
            src: async (query) => {
                try {
                    let source = await fetch(SUGGEST_ENDPOINT);
                    return await source.json();
                } catch (error) {
                    return error;
                }
            },
            keys: null
        },
        debounce: 300,
        placeHolder: "Search",
    };
    ac = new autoComplete({config});
}

Every time I reload the site, I get this error in the console:

[Error] Unhandled Promise Rejection: TypeError: el is not an Object. (evaluating 'key in el')
    create (autoComplete.js:182)
    (anonymous function) (autoComplete.js:557)
    Promise
    init (autoComplete.js:547)
    autoComplete (autoComplete.js:649)
    (anonymous function) (core.js:35)

What's happening here?

folknor commented 2 years ago

Change

ac = new autoComplete({config});

to

ac = new autoComplete(config);
SamusAranX commented 2 years ago

Well, that was easy. Please adjust the usage instructions here (https://tarekraafat.github.io/autoComplete.js/#/usage?id=_2-script) because they currently tell you to do what I did.

clementmas commented 2 years ago

I agree, the instructions new autoComplete({ config }) are misleading. I had the same issue.