Typeahead code?

I want to add code for typeahead (so when users enter letters in the search box, it automatically shows suggestion of completion based on the product names / product suggestions) in the on.ready function but I don’t really know how to do that.
Can somebody please help me?

Hi Codrin,

You can use the onKeyPress() event handler of your text input field to get the latest value. Then, use that value in a query (search) of the database. Something like this:

let value = $w("#input1").value;
wixData.query("collection")
  .startsWith("names", value)
  .find()
  .then( (results) => {
 // result for your dropdown
  } )
  .catch( (error) => {
 let errorMsg = error.message;
 let code = error.code;
  } );

You can create a dropdown using a Repeater using the technique in the post Hey, you! Repeater! Stop shoving!

Good luck,

Yisrael