multiple database field search
19 Restaurants
import wixData from 'wix-data';
let debounceTimer;
$w.onReady(() => {
$w("#searchInputID").onKeyPress(function () {
$w("#xIconID").show();
$w("#searchInputID").value;
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchInputID").value);
}, 200);
})
let searchWord;
function filter(search) {
if (searchWord !== search) {
$w("#datasetID").setFilter(wixData.filter().contains('fieldkey1', search)
.or(wixData.filter().contains("fieldkey2", search))
//Insert more field filter here ====> here <====
)
.then(countItems)
searchWord = search
}
}
//COUNT SEARCH FUNCTION 🚀
function countItems() {
let count = $w("#datasetID").getTotalCount()
count > 0 ? $w("#countTextID").text = `${count} Restaurants` : $w("#countTextID").text = `No Restaurants Found 😥`;
return countItems;
}
//LOAD COUNT WHEN DATASET IS READY 🎉
$w("#datasetID").onReady(function () {
countItems();
});
// CLEAR SEARCH CODE 🎉
$w('#xIconID').onClick(() => {
$w("#searchInputID").value = undefined
$w("#datasetID").setFilter(wixData.filter()).then(countItems())
$w("#xIconID").hide();
})
})