@yisrael-wix I have finally had a chance to try this. Works great except having an issue about clearing out the search for another search on return. There are times it will not function in changing out search (when you backspace to clear the search), etc. Can a clear search be coded for this same code. Or do I have this in wrong place in my code…I notice your code does not have this on change for the word search box. I have keypress and on change for the search box #iTitle and on change for the drop down iCategory
export function iTitle_change(event) {
}
My page: https://www.ourozarks.com/search
My code:
import wixData from “wix-data”;
import {local} from ‘wix-storage’;
const PREV_COMBINATION = ‘PREV_COMBINATION’;
const PREV_CATEGORY = ‘PREV_CATEGORY’;
let lastFilterCombination
let lastFilterCategory;
$w.onReady(() => {
loadEXPLORE();
});
let debounceTimer
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterCategory);
}, 500);
}
export function iCategory_change(event) {
filter(lastFilterCombination, $w(‘#iCategory’).value);
}
function filter(title, category) {
if (lastFilterCombination !== title || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘combination’, title);
if (category)
newFilter = newFilter.contains(‘category’, category);
$w(‘#dataset6’).setFilter(newFilter);
lastFilterCombination = title;
lastFilterCategory = category;
}
if (title)
local.setItem(PREV_COMBINATION, title);
else
local.removeItem(PREV_COMBINATION);
if (category)
local.setItem(PREV_CATEGORY, category);
else
local.removeItem(PREV_CATEGORY);
}
function loadEXPLORE() {
wixData.query(‘EXPLORE’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘ALL CATEGORIES’}];
options.push(…res.items.map(category => {
return {“value”: category.title, “label”: category.title};
}));
$w(‘#iCategory’).options = options;
loadPrevSearch();
});
}
function loadPrevSearch() {
let prevCombination = local.getItem(PREV_COMBINATION);
let prevCategory = local.getItem(PREV_CATEGORY);
if (prevCombination) {
$w(‘#iTitle’).value = prevCombination;
}
debugger ;
if (prevCategory) {
$w(‘#iCategory’).value = prevCategory;
}
if (prevCombination || prevCategory) {
filter(prevCombination, prevCategory);
}
}
export function iTitle_change(event) {
}