Hello I found below code in some old post and I’m trying to figure out how to make it work.
I have a data collection with more than 3k item and I need to let the user pick one of the item.
I divided the 3k items into few categories and I created second dropdown menu in order to filter them but that’s not good,the user need to be able to type the name of one of the item and choose it in a dropdown menu without prior filter.
This code looks good enough but I can’t find a place to put i.
I have an input text and drop down, should I put it under on click event? Or when page is loaded function?
“The below code will search a database column (“fieldKey”) for items that match the value you type into your input box. Change the following variables : (DatabaseID, fieldKey, input1, dropdown1) async function getUniqueListFromDatabase() { const List1 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(”#input1").value) .limit(1000) .ascending(“fieldKey”) .find() const List2 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(“#input1”).value) .limit(1000) .skip(1000) .ascending(“fieldKey”) .find() const List3 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(“#input1”).value) .limit(1000) .skip(2000) .ascending(“fieldKey”) .find() const List4 = await wixData.query(“DatabaseID”) .contains(“fieldKey”, $w(“#input1”).value) .limit(1000) .skip(3000) .ascending(“fieldKey”) .find() const mergedLists = List1.items.concat(List2.items).concat(List3.items).concat(List4.items) const uniqueItems = getUniqueTitles(mergedLists); $w(“#dropdown1”).options = buildOptions(uniqueItems); function getUniqueTitles(items) { const titlesOnly = items.map(item => item.fieldKey); // don’t forget to change this field key return […new Set(titlesOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return { label: curr, value: curr }; }); } }"
Thank you!