Brand new to coding, but I followed the example precisely from this tutorial: Conditional Filtering for Dropdowns on Wix | Corvid Tutorial - YouTube
My database has three fields: “region,” “country,” and “project”
I get the first dropdown list (“region”) to function properly, but the subsequent dropdowns do nothing. Here’s my code:
import wixData from ‘wix-data’;
$w.onReady( function () {
uniqueDropDown1();
});
function uniqueDropDown1() {
wixData.query(“locations”)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#regionDropdown1”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.region);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };
});
}
}
export function region_change(event, $w) {
uniqueDropDown2();
$w(“#countryDropdown”).enable();
}
function uniqueDropDown2() {
wixData.query(“locations”)
.contains(“country”, $w(“#regionDropdown1”).value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#countryDropdown”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.country);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };
});
}
}
export function country_change(event, $w) {
uniqueDropDown3();
$w(“#regionDropdown”).enable();
}
function uniqueDropDown3() {
wixData.query(“locations”)
.contains(“project”, $w(“#projectDropdown”).value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w(“#projectDropdown”).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.project);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return { label: curr, value: curr };
});
}
}
Thanks for any help!