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

Uncaught (in promise) TypeError: right-hand side of 'in' should be an object, got null

Open DmitiyPi opened this issue 2 years ago • 5 comments

window.onload = function() { const autoCompleteJS = new autoComplete({ config }); };

DmitiyPi avatar Apr 01 '22 16:04 DmitiyPi

You've probably made the same mistake as https://github.com/TarekRaafat/autoComplete.js/issues/298 but it's hard to tell without you showing more of your code.

folknor avatar Apr 01 '22 21:04 folknor

I got the same error message. My problem was a wrong selector selector: 'search' instead of selector: '#search'.

clementmas avatar Jun 03 '22 11:06 clementmas

In my case, I defined the autocomplete engine before the autocomplete element was defined. Either move the engine definition to later in your html, or wrap it in a function you call at the end.

Danferno avatar Jun 14 '22 12:06 Danferno

I ran into the same error:

let autoCompleteJS = new autoComplete({
                selector: "#branch",
                data: {
                    src: async (query) => {
                        try {
                            const source = await fetch(`/suggestor/${query}`);
                            const data = await source.json();
                            return data;
                        } catch (error) {
                            return error;
                        }
                    }
                },
                resultItem: {
                    highlight: true,
                },
                events: {
                    input: {
                        focus: () => {
                            if (autoCompleteJS.input.value.length) autoCompleteJS.start();
                        },
                        selection: (event) => {
                            const feedback = event.detail;
                            autoCompleteJS.input.blur();
                            const selection = feedback.selection.value;
                            autoCompleteJS.input.value = selection;
                        }
                    }
                }
            });

Erando89 avatar May 31 '23 12:05 Erando89

@TarekRaafat I am having the same issue with v10.2.7 when I try to use the name config setting. I investigated it a bit, and the root cause seems to be this line here: https://github.com/TarekRaafat/autoComplete.js/blob/220ada635256839923bd68e358ee2761fa84e010/src/autoComplete.js#L56 The name is set in two places in the autoComplete constructor: the this.name property, and as a name field in the this.options property. https://github.com/TarekRaafat/autoComplete.js/blob/220ada635256839923bd68e358ee2761fa84e010/src/autoComplete.js#L53-L56 The this.name property is hardcoded, and the name field in the this.options parameter is not actually used in the configuring stage: https://github.com/TarekRaafat/autoComplete.js/blob/220ada635256839923bd68e358ee2761fa84e010/src/services/configure.js#L9-L28 so it throws the TypeError as soon as it tries to create the wrapper.

I'd imagine that the solution is to set this.name = config['name'] ?? 'autoComplete', but you can make the call on that.

striker4150 avatar Jun 14 '23 01:06 striker4150