Hi all
I followed wix tutorial “Search a Database” with search box and a dropdwon filter. All works fine APART form one thing. When I try to code it to search two fields in the database it doesn’t work.
If someone inputs a search criteria in the “Search Boxr” I need to search / filter results from “TWO” fields within the database i’m connecting it to, not just one.
Everything I’ve tried breaks the code and doesn’t work.
When I try to add an additional filter for filtering the “SKILLS” field of the databse together with the "JOB TITLE field it won’t work.
Any advice / help would be more than appreciated. Code I have to date is as follows
import wixData from "wix-data";
$w.onReady(() => {
loadLIVEJOBS();
});
let lastFilterjobTitle;
let lastFilterlocation;
let debounceTimer;
export function searchtitle_keyPress(event) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#searchtitle').value, lastFilterlocation);
}, 500);
}
export function searchlocation_change(event) {
filter(lastFilterjobTitle, $w('#searchlocation').value);
}
function filter(jobtitle, location) {
if (lastFilterjobTitle !== jobtitle || lastFilterlocation !== location) {
let newFilter = wixData.filter();
if (jobtitle)
newFilter = newFilter.contains('jobTitle', jobtitle);
if (location)
newFilter = newFilter.contains('location', location);
$w('#livejobsdata').setFilter(newFilter);
lastFilterjobTitle = jobtitle;
lastFilterlocation = location;
}
}
function loadLIVEJOBS() {
wixData.query('LIVEJOBS')
.find()
.then(res => {
let options = [{ "value": '', "label": 'All Locations' }];
options.push(...res.items.map(location => {
return { "value": location.location, "label": location.location };
}));
$w('#searchlocation').options = options;
});
}