autoComplete.js
autoComplete.js copied to clipboard
Uncaught (in promise) TypeError: right-hand side of 'in' should be an object, got null
window.onload = function() { const autoCompleteJS = new autoComplete({ config }); };
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.
I got the same error message. My problem was a wrong selector selector: 'search'
instead of selector: '#search'
.
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.
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;
}
}
}
});
@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.