Hi all, would really appreciate some help connecting my dropdown functions to a repeater.
I’ve used code to allow three dropdowns that filter down based on selection. This is all connected up and works great.
My struggle telling those dropdowns to display the relevant content in my repeater once all three dropdowns.
I’ve half managed to get it working and on some dropdown selections it displays the correct content, then on others it either displays multiples of the correct content or just pulls blank. My code knowledge isn’t good enough to figure out where I’m going wrong. PLEASE HELP!
The current page is here >> https://www.review.dupreefs.com/newbuilds-book
And please see the code i’ve used below:
import wixData from 'wix-data';
$w.onReady(function () {
uniqueDropDown1();
});
function uniqueDropDown1 (){
wixData.query("Dupree_NewBuild_Booking")
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#sitedropdown").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.site);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}
export function sitedropdown_change(event, $w) {
uniqueDropDown2();
$w("#locationdropdown").enable();
}
function uniqueDropDown2 (){
wixData.query("Dupree_NewBuild_Booking")
.contains("site", $w("#sitedropdown").value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#locationdropdown").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.location);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}
export function locationdropdown_change(event, $w) {
uniqueDropDown3();
$w("#advisordropdown").enable();
}
function uniqueDropDown3 (){
wixData.query("Dupree_NewBuild_Booking")
.contains("location", $w("#locationdropdown").value)
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#advisordropdown").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.advisor);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}
$w.onReady(function () {
$w("#Button").onClick(()=>{ $w("#newbuilddataset").setFilter(wixData.filter()
.eq("site", $w("#sitedropdown").value)
.eq("location", $w("#locationdropdown").value)
.eq("advisor", $w("#advisordropdown").value));
});
});