
Conditional Dropdown Filter
Paris Spaghetti
Italian, French
London, Worldwide
Potato House Diner
Italian, French
Worldwide, London
Rolled & Scrambled Eggs
French
Worldwide
The Roasted Chicken
French
London
Chips & Pastry
Italian
London
Yellow Cab
Italian
Worldwide
Page Code
import wixData from 'wix-data';
import { restaurantLocation, restaurantCuisine, worldwideRestaurants, londonRestaurants } from 'public/Restaurant.js';
//Search function
export function search_click(event) { //Button onClick event
$w("#dataset1").setFilter(wixData.filter() //Set dataset to filter
.contains("location", $w("#restaurantLocation").value) //location field key and dropdown
.contains("title", $w("#Restaurant").value) //Restaurant field key and dropdown
.contains("cuisine", $w("#restaurantCuisine").value)) //Cuisine field key and dropdown
$w("#repeater1").expand; //Repeater expands after filter
}
//Conditional Dropdown
$w.onReady(function () {
$w('#restaurantLocation').options = restaurantLocation;
$w('#restaurantLocation').placeholder = 'All locations';
$w('#restaurantLocation').onChange(() => {
let location = $w("#restaurantLocation").value
$w("#dataset1").setFilter(wixData.filter()
.eq('location', location))
if ($w('#restaurantLocation').value === 'Worldwide') {
$w('#restaurantCuisine').options = restaurantCuisine;
$w('#restaurantCuisine').placeholder = 'Worldwide Resto';
$w('#Restaurant').options = worldwideRestaurants;
$w('#Restaurant').placeholder = 'Restaurants';
$w('#Restaurant').enable();
$w('#restaurantCuisine').enable();
} else if ($w('#restaurantLocation').value === 'London') {
$w('#restaurantCuisine').options = restaurantCuisine;
$w('#restaurantCuisine').placeholder = 'London Cuisines';
$w('#Restaurant').options = londonRestaurants;
$w('#Restaurant').placeholder = 'Restaurants';
$w('#Restaurant').enable();
$w('#restaurantCuisine').enable();
}
});
});
Copied!
Public.js Code
//Location Dropdown Options
export const restaurantLocation = [
{ value: "", label: "Select Location" },
{ value: "London", label: "London" },
{ value: "Worldwide", label: "Worldwide" },
];
//Cuisine Dropdown Options
export const restaurantCuisine = [
{ value: "Italian", label: "Italian" },
{ value: "French", label: "French" }
]
//Restaurant Dropdown Options (Worldwide)
export const worldwideRestaurants = [
{ value: "Paris Spaghetti ", label: "Paris Spaghetti " },
{ value: "Rolled & Scrambled Eggs", label: "Rolled & Scrambled Eggs" },
{ value: "Potato House Diner", label: "Potato House Diner" },
{ value: "Yellow Cab", label: "Yellow Cab" },
]
//Restaurant Dropdown Options (London)
export const londonRestaurants = [
{ value: "Paris Spaghetti", label: "Paris Spaghetti" },
{ value: "Chips & Pastry", label: "Chips & Pastry" },
{ value: "Potato House Diner", label: "Potato House Diner" },
{ value: "The Roasted Chicken", label: "The Roasted Chicken" },
]