This code was working yesterday but for some reason today it is not and I am not sure why.
let OptionsHolder = [
{"label": "One", "value": "A"},
{"label": "Two", "value": "B"},
{"label": "Three", "value": "C"}
]
$w("dropdown3").options = OptionsHolder
The code above works and the dropdown box holds the options, however whenever I try to set a value it removes all the options from the dropdown so the dropdown section is just a little black bar.
let OptionsHolder = [
{"label": "One", "value": "A"},
{"label": "Two", "value": "B"},
{"label": "Three", "value": "C"}
]
$w("#dropdown3").options = OptionsHolder
// Works
let SelectedValue = "A"
$w("#dropdown3").value = SelectedValue
I have run tests, the value the Dropdown box is set to is the same as the value in the OptionsHolder.
Tests:
if (OptionsHolder[0].value === SelectedValue) {
console.log("True") // This is returned
}
console.log($w("#dropdown3").options) // Returns OptionsHolder
console.log($w("#dropdown3").value) // Returns "A"
Does anyone know what it is not working?
The blank dropdown after the value was set:
All right, so I found a rather strange solution.
I tried changing the ID of the Dropdown to another I already had on the page and that worked, I am not sure why.
I tried adding a button that sets the value and that worked so now my solution is this:
let OptionsHolder = [{"label": "One", "value": "A"}, {"label": "Two", "value": "B"}, {"label": "Three", "value": "C"} ] $w("#dropdown3").options = OptionsHolder // Works let SelectedValue = "A" Button_onClick() export function Button_onClick() { $w("#dropdown3").value = SelectedValue }
My guess as to why this is working so strangle is that I modified the the dropdown box while it was working and then as the site was saving my browser crashes, so maybe it mess something up then?
Do you see any error in the console?