Hi
Hoping someone can help! I have coded the first ‘searchBar’ to filter by multiple searchwords in multiple fields. I would like the second search bar ‘searchLocation’ to refine the results by searching database fields ‘location’ and ‘extraAddress’. I have been trying different code, with no luck. This is the code I have so far, any help would be greatly appreciated:
import wixData from ‘wix-data’;
let debounceTimer;
$w.onReady(() => {
$w("#searchBar").onKeyPress(function () {
$w("#image6").show();
$w("#searchBar").value;
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchBar").value);
}, 200);
})
let searchWord;
function filter(search) {
if (searchWord !== search) {
$w("#dataset1").setFilter(wixData.filter().contains('title', search)
.or(wixData.filter().contains("dinner", search))
.or(wixData.filter().contains("lunch", search))
.or(wixData.filter().contains("breakfast", search))
.or(wixData.filter().contains("allergy", search))
.or(wixData.filter().contains("eveningMenu", search))
.or(wixData.filter().contains("lunchMenuRead", search))
. or(wixData.filter().contains("cocktailMenu", search))
. or(wixData.filter().contains("wineMenu", search))
. or(wixData.filter().contains("veganOptions", search))
//Insert more field filter here ====> here <====
)
.then(countItems)
searchWord = search
}
}
//COUNT SEARCH FUNCTION 🚀
function countItems() {
let count = $w("#dataset1").getTotalCount()
count > 0 ? $w("#textResults").text = `${count} Eateries` : $w("#textResults").text = `No Eateries Found 😥`;
return countItems;
}
//LOAD COUNT WHEN DATASET IS READY 🎉
$w("#dataset1").onReady(function () {
countItems();
});
// CLEAR SEARCH CODE 🎉
$w('#image6').onClick(() => {
$w("#searchBar").value = undefined
$w("#dataset1").setFilter(wixData.filter()).then(countItems())
$w("#image6").hide();
})
})