Well first thing!
Never use more then just ONE —> onReady() in your code.
Second, here you can see an upgraded version of your —> Get unique titles-function…
Instead of coding it for every single dropdown, you can use my shown code for all your dropdowns. I hope you will understand how to implement and use this CODE-SNIPET.
import wixData from 'wix-data';
var DATABASE = "your Collection-Name here"
var DropDowns=[]
var DDprefix "DD" ; //ID-prefix of all your dopdowns (DD1, DD2..)
//----------------------------------|
DropDowns[0] = "reference-column1" ; //column in your DATABASE ("title")
DropDowns[1] = "reference-column2" ; //column in your DATABASE
DropDowns[2] = "reference-column3" ; //column in your DATABASE
DropDowns[3] = "reference-column4" ; //column in your DATABASE
DropDowns[4] = "reference-column5" ; //column in your DATABASE
DropDowns[5] = "reference-column6" ; //column in your DATABASE
DropDowns[6] = "reference-column7" ; //column in your DATABASE
DropDowns[7] = "reference-column8" ; //column in your DATABASE
DropDowns[8] = "reference-column9" ; //column in your DATABASE
DropDowns[9] = "reference-column10" ; //column in your DATABASE
//----------------------------------|
async function uniqueTitles_DropDowns() {
console.log("load_UniqueTitles for DropDowns")
let dbDATA = await wixData.query(DATABASE)
let Options = []
for (var a = 0; a < DropDowns.length; a++) {
if(DropDowns[a]!==undefined && DropDowns[a]!=="undefined" && DropDowns[a]!==null) {
await dbDATA.distinct(DropDowns[a])
.then((results) => {
let items = results.items
for (var b = 0; b <items.length; b++) {
Options.push([])
Options[a].push({"label": items[b], "value": items[b]})
}
$w('#'+DDprefix+(a+1)).options = Options[a]
$w('#'+DDprefix+(a+1)).placeholder = DropDowns[a]
})
}
}
}
$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));
});
});
+++++++++++++++ (combination)
$w.onReady(function () {
uniqueDropDown1();
});
=============== (result)
$w.onReady(function () {
uniqueDropDown1();
$w("#Button").onClick(()=>{
$w("#newbuilddataset").setFilter(wixData.filter()
.eq("site", $w("#sitedropdown").value)
.eq("location", $w("#locationdropdown").value)
.eq("advisor", $w("#advisordropdown").value));
});
});
Your CODE could look like this…
import wixData from 'wix-data';
//------------[User-Interface-----------------------------------------------------|
var DATABASE = "your Collection-Name here"
var DropDowns=[]
var DDprefix "DD" ; //ID-prefix of all your dopdowns (DD1, DD2..)
//----------------------------------|
DropDowns[0] = "reference-column1" ; //column in your DATABASE ("title")
DropDowns[1] = "reference-column2" ; //column in your DATABASE
DropDowns[2] = "reference-column3" ; //column in your DATABASE
DropDowns[3] = "reference-column4" ; //column in your DATABASE
DropDowns[4] = "reference-column5" ; //column in your DATABASE
DropDowns[5] = "reference-column6" ; //column in your DATABASE
DropDowns[6] = "reference-column7" ; //column in your DATABASE
DropDowns[7] = "reference-column8" ; //column in your DATABASE
DropDowns[8] = "reference-column9" ; //column in your DATABASE
DropDowns[9] = "reference-column10" ; //column in your DATABASE
//------------[User-Interface-----------------------------------------------------|
//------------starting CODE-part when page loads.....
$w.onReady(function () {
load_uniqueTitles_DropDowns();
$w("#Button").onClick(()=>{
$w("#newbuilddataset").setFilter(wixData.filter()
.eq("site", $w("#sitedropdown").value)
.eq("location", $w("#locationdropdown").value)
.eq("advisor", $w("#advisordropdown").value));
});
$w('#sitedropdown').onChange(()=>{
$w("#locationdropdown").enable();
})
$w('#locationdropdown').onChange(()=>{
$w("#advisordropdown").enable();
})
});
//-----loading of DropDown-Unique-Titles for all given DropDowns.....
async function load_uniqueTitles_DropDowns() {
console.log("Load uniqueTitles for DropDowns")
let dbDATA = await wixData.query(DATABASE)
let Options = []
for (var a = 0; a < DropDowns.length; a++) {
if(DropDowns[a]!==undefined && DropDowns[a]!=="undefined" && DropDowns[a]!==null) {
await dbDATA.distinct(DropDowns[a])
.then((results) => {
let items = results.items
for (var b = 0; b <items.length; b++) {
Options.push([])
Options[a].push({"label": items[b], "value": items[b]})
}
$w('#'+DDprefix+(a+1)).options = Options[a]
$w('#'+DDprefix+(a+1)).placeholder = DropDowns[a]
})
}
}
}