trevoreyre / autocomplete

Accessible autocomplete component for vanilla JavaScript and Vue.
https://autocomplete.trevoreyre.com
MIT License
427 stars 76 forks source link

Search with offline data is not working. #168

Open ThomasSuchalla opened 5 months ago

ThomasSuchalla commented 5 months ago

When I try to test the following example with offline data, the following message always appears. Documentation: https://autocomplete.trevoreyre.com/#/javascript-component?id=baseclass Message: Uncaught TypeError: l is not a function

Example: https://jsfiddle.net/3aztrv6n/

evanwills commented 4 months ago

Hi @ThomasSuchalla

From looking at your fiddle, I think you haven't passed the search function as one of the properties when calling

new Autocomplete('.search', { baseClass: 'search' });

e.g.


const offLineSearch = (input) => {
   const _input = input.toLowerCase();
   const options = ['First result', 'Second result'];

   return options.filter((option) => option.toLowerCase().includes(_input));
};

new Autocomplete('.search', { 
  baseClass: 'search',
  search: offLineSearch,
});

The search function can include your offline data.

Note: you don't need to include the offline options in the HTML. The search function will handle all that for you.

See https://codepen.io/evanwills/pen/xxBBzOy for a working example