Hello - Can someone help with this code? I copied it from WIX ( https://www.wix.com/corvid/forum/wix-tips-and-updates/how-to-create-a-search-for-your-database
https://www.youtube.com/watch?v=Hx7_8-lRsW0&feature=youtu.be ) and changed it to my variables and it works for the search for city, and search for state.
It doesn't work however, for the ALL STATES entry in my dropdown as a reset. Can someone advise how to change this code so that ALL STATES selection returns to the default page of all results from the dbase / Or can someone advise how to disengage the search after searches are complete, so that the page returns to all results to match the default load of the page / or can someone advise how to include a button that will 'refresh' the page to remove the prior search input?
Short version - how to reset my page after a search because per below, it always holds the previous search and no where in the code below to reset the page back to ALL results? The ALL STATES option works successfully on the wix page example, but doesn't do the same on my page - any advice? Please and thank you - Brian
###
import wixData from "wix-data";
$w.onReady(() => {
loadModelSubmissions()();
});
let lastFilterCity;
let lastFilterState;
let debounceTimer;
export function iCity_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iCity').value, lastFilterState);
}, 500);
}
export function iState_change_1(event, $w) {
filter(lastFilterCity, $w('#iState').value);
}
function filter(city, state) {
if (lastFilterCity !== city || lastFilterState !== state) {
let newFilter = wixData.filter();
if (city)
newFilter = newFilter.contains('city', city);
if (state)
newFilter = newFilter.contains('state', state);
$w('#dataset1').setFilter(newFilter);
lastFilterCity = city;
lastFilterState = state;
}
}
function loadModelSubmissions() {
wixData.query('State')
.find()
.then(res => {
let options = [{"value": '', "label": 'All States'}];
options.push(...res.items.map(state => {
return {"value": state.city, "label": state.city};
}));
$w('#iState').options = options;
});
}