If there is better solution please suggest new direction. I have read, studied and learned much. BTW I have coded many, many years. This is kicking my A**
I have a collection with locations.
I have a collection with state names
I have a collection with county names ( State have counties)
I have drop downs for State and County.
I want the county dropdown empty until a state is selected.
I have am not connecting any data in the county dropdown. Seems like I should be able to do this with hand code.
export function statedropdown_change(event, $w) IS working.
This calls locationCountyFilter()
function locationCountyFilter()
calls async function queryCounty(seletedState)
async function queryCounty(seletedState)
It seems that this function is not operating in sequence and returns an unknown obj type that causes and error.
(note: I have tried this for many hours with .then with anything working. )
This is my LOG for code below.
A 1 queryReturnList before call: ** undefined
B 1 IN queryCounty Function
A 2 queryReturnList after call: [object Promise]** undefined << line 40
TypeError: queryReturnList.forEach is not a function << line 41
B 2
countyNames: Monroe,Paulding,Polk,Rockdale,Spalding,Fayette,Floyd,Forsyth,Fulton,Gwinnett,Hall,Henry,Lumpkin,Bartow,Carroll,Cherokee,Cobb,Coweta,Dawson,Dekalb,Douglas undefined
B 3
I would think the sequence should be A1, B1, B2, B3, A2
export function statedropdown_change(event, $w) {
console.log(">>>>>>>>>>> func statedropdown change" + $w("#statedropdown").value)
$w('#countydropdown').options = [];
$w("#countydropdown").enable();
locationCountyFilter()
}
function locationCountyFilter() {
let userSelectedState = $w("#statedropdown").value
let queryReturnList = []
console.log(" A 1 queryReturnList before call: " + queryReturnList + "** " + queryReturnList.type)
queryReturnList = queryCounty(userSelectedState)
console.log(" A 2 queryReturnList after call: " + queryReturnList + "** " + queryReturnList.type)
queryReturnList.forEach((element) => {
console.log("for each element: " + element.county)
$w('#countydropdown').options.push({ "label": element, "value": element });
})
console.log(" A 3 ")
$w('#countydropdown').enable();
$w("#statedropdown").enable();
filterLocations()
}
async function queryCounty(seletedState) {
console.log(" B 1 IN queryCounty Function")
let results = await wixData.query("counties")
.eq("state", seletedState)
.eq("use", "1")
.find()
console.log(" B 2 ")
let res = results.items
let countyNames = []
res.forEach((element) => {
countyNames.push(element.county)
})
console.log("countyNames: " + countyNames + " " + countyNames.type)
console.log(" B 3 ")
return countyNames
}