Hi,
I’m trying to create a set of filters on a page using a repater and I have followed this turtorial LINK which I have successfulling working but is there a way I can amend the code to allow the search input to filter from two different fields in the data collection ( title and location ).
Working code with only one field (title)
import wixData from "wix-data";
//working do not edit
$w.onReady(() => {
loadHowFarList();
});
let lastFilterTitle;
let lastFilterHow_Far;
let debounceTimer;
export function iadventures_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iadventures').value, lastFilterHow_Far);
}, 500);
}
export function iFar_change(event, $w) {
filter(lastFilterTitle, $w('#iFar').value);
}
function filter(title, howFar) {
if (lastFilterTitle !== title || lastFilterHow_Far !== howFar) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains('title', title);
if (howFar)
newFilter = newFilter.contains('howFar', howFar);
$w('#dataset6').setFilter(newFilter);
$w('#dataset5').setFilter(newFilter);
lastFilterTitle = title;
lastFilterHow_Far = howFar;
}
}
function loadHowFarList() {
wixData.query('HowFarList')
.find()
.then(res => {
let options = [{"value": '', "label": 'All Walks'}];
options.push(...res.items.map(howFar => {
return {"value": howFar.title, "label": howFar.title};
}));
$w('#iFar').options = options;
});
}
I have spend hours amending it in various combinations with no luck
I saw on another thread the code below (I have changed the IDs) but I can’t work out where to place it so it almosted worked… it allowed to search both title and locaton BUT it disabled the dropdown box (howfar)
$w("#dataset6").setFilter(wixData.filter()
.contains("title", $w("#iadventures").value)
.or(wixData.filter()
.contains("location", $w("#iadventures").value))
.or(wixData.filter()
Many thanks,
Dean