Hello-
My current code is set up for 2 dropdowns and search bar. It works perfectly but when I add the 3rd drop down my code breaks and the search bar no longer works. Help!
Current Code:
import { local } from ‘wix-storage’;
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchbar1”).value = sameWord;
$w(‘#members’).onReady( function () {
filter($w(‘#searchbar1’).value, lastFilterLocation, lastFilterPrice);
}, 200);
});
$w.onReady(() => {
loadLocations();
});
$w.onReady(() => {
loadPrice();
});
$w.onReady(() => {
local.clear(“#searchbar1”);
});
let lastFilterSearchbar;
let lastFilterLocation;
let lastFilterPrice;
let debounceTimer;
export function searchbar1_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#searchbar1’).value, lastFilterLocation, lastFilterPrice);
}, 200);
}
export function searchbar1_change() {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#searchbar1’).value, lastFilterLocation, lastFilterPrice);
}, 500);
}
export function location_change(event, $w) {
filter(lastFilterSearchbar, $w(‘#location’).value);
}
export function price_change(event, $w) {
filter(lastFilterSearchbar, lastFilterLocation, $w(‘#price’).value);
}
function filter(searchbar, location, price) {
if (lastFilterSearchbar !== searchbar || lastFilterLocation !== location || lastFilterPrice !== price) {
let newFilter = wixData.filter();
if (searchbar)
newFilter = newFilter.contains(‘title’, searchbar)
.or = newFilter.contains(‘cuisines’ || ‘features’ || ‘categories’ || ‘catergory1’ || ‘category2’, searchbar)
if (location)
newFilter = newFilter.contains(‘location’, location);
if (price)
newFilter = newFilter.contains(‘price’, price);
$w(‘#members’).setFilter(newFilter)
.then(() => {
console.log(“Dataset is now filtered”);
if ($w(‘#members’).getTotalCount() === 0) {
$w(‘#nores’).show();
} else {
$w(‘#nores’).hide();
}
})
. catch ((err) => {
console.log(err);
});
lastFilterSearchbar = searchbar;
lastFilterLocation = location;
lastFilterPrice = price;
}
}
function loadLocations() {
wixData.query(‘members’)
.find()
.then(res => {
let options = [{ “value”: ‘’, “label”: ‘All Locations’ }];
options.push(…res.items.map(location => {
return { “value”: location.searchbar, “label”: location.price.searchbar };
}));
$w(‘#location’).options = options;
});
}
function loadPrice() {
wixData.query(‘members’)
.find()
.then(res => {
let options = [{ “value”: ‘’, “label”: ‘All Prices’ }];
options.push(…res.items.map(price => {
return { “value”: price.searchbar, “label”: price.location.searchbar };
}));
$w(‘#price’).options = options;
});
}
let slideInOptions = {
“duration”: 200,
};
let slideOutOptions = {
“duration”: 200,
};
export function clear_click(event, $w) {
$w(“#location”).value = ‘Location’;
$w(“#price”).value = ‘Price’;
$w(“#cuisine”).value = ‘Cuisine’;
$w(“#searchbar1”).value = undefined;
$w(“#members”).setFilter(wixData.filter());
}
CODE FOR NEW DROPDOWN (Cuisine) , Dataset Column is “Cuisines”
import { local } from ‘wix-storage’;
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
$w.onReady( function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchbar1”).value = sameWord;
$w(‘#members’).onReady( function () {
filter($w(‘#searchbar1’).value, lastFilterLocation, lastFilterPrice, lastFilterCuisine);
}, 200);
});
$w.onReady(() => {
loadLocations();
});
$w.onReady(() => {
loadPrice();
});
$w.onReady(() => {
loadCuisine();
});
$w.onReady(() => {
local.clear(“#searchbar1”);
});
let lastFilterSearchbar;
let lastFilterLocation;
let lastFilterPrice;
let lastFilterCuisine;
let debounceTimer;
export function searchbar1_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#searchbar1’).value, lastFilterLocation, lastFilterPrice, lastFilterCuisine);
}, 200);
}
export function searchbar1_change() {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#searchbar1’).value, lastFilterLocation, lastFilterPrice, lastFilterCuisine);
}, 500);
}
export function location_change(event, $w) {
filter(lastFilterSearchbar, $w(‘#location’).value);
}
export function price_change(event, $w) {
filter(lastFilterSearchbar, lastFilterLocation, $w(‘#price’).value);
}
export function cuisine_change(event, $w) {
filter(lastFilterSearchbar, lastFilterPrice, $w(‘#cuisine’).value); }
function filter(searchbar, location, price, cuisine) {
if (lastFilterSearchbar !== searchbar || lastFilterLocation !== location || lastFilterPrice !== price || lastFilterCuisine !== cuisine) {
let newFilter = wixData.filter();
if (searchbar)
newFilter = newFilter.contains(‘title’, searchbar)
.or = newFilter.contains(‘cuisines’ || ‘features’ || ‘categories’ || ‘catergory1’ || ‘category2’, searchbar)
if (location)
newFilter = newFilter.contains(‘location’, location);
if (price)
newFilter = newFilter.contains(‘price’, price);
if (cuisine)
newFilter = newFilter.contains(‘cuisines’, cuisine);
$w(‘#members’).setFilter(newFilter)
.then(() => {
console.log(“Dataset is now filtered”);
if ($w(‘#members’).getTotalCount() === 0) {
$w(‘#nores’).show();
} else {
$w(‘#nores’).hide();
}
})
. catch ((err) => {
console.log(err);
});
lastFilterSearchbar = searchbar;
lastFilterLocation = location;
lastFilterPrice = price;
lastFilterCuisine = cuisine;
}
}
function loadLocations() {
wixData.query(‘members’)
.find()
.then(res => {
let options = [{ “value”: ‘’, “label”: ‘All Locations’ }];
options.push(…res.items.map(location => {
return { “value”: location.searchbar, “label”: location.price.searchbar };
}));
$w(‘#location’).options = options;
});
}
function loadPrice() {
wixData.query(‘members’)
.find()
.then(res => {
let options = [{ “value”: ‘’, “label”: ‘All Prices’ }];
options.push(…res.items.map(price => {
return { “value”: price.searchbar, “label”: price.location.searchbar };
}));
$w(‘#price’).options = options;
});
}
function loadCuisine() {
wixData.query(‘members’)
.find()
.then(res => {
let options = [{ “value”: ‘’, “label”: ‘All Cuisines’ }];
options.push(…res.items.map(cuisine => {
return { “value”: cuisine.searchbar, “label”: cuisine.price.location.searchbar };
}));
$w(‘#cuisine’).options = options;
});
}
let slideInOptions = {
“duration”: 200,
};
let slideOutOptions = {
“duration”: 200,
};
export function clear_click(event, $w) {
$w(“#location”).value = ‘Location’;
$w(“#price”).value = ‘Price’;
$w(“#cuisine”).value = ‘Cuisine’;
$w(“#searchbar1”).value = undefined;
$w(“#members”).setFilter(wixData.filter());
}
Once this code is added this section breaks
if (searchbar) newFilter = newFilter.contains(‘title’, searchbar) .or = newFilter.contains(‘cuisines’ || ‘features’ || ‘categories’ || ‘catergory1’ || ‘category2’, searchbar)
and my Cuisine dropdown doesn’t work either.