Cannot set dropdown value using code

Hi everyone,

I have a dropdown of which I am setting the value (taken from a dynamic dataset) using code. But after setting the value, the placeholder text just stays visible and the validity of the dropdown goes to false (and its borders turn red).

Basic code snippet:

let item = $w("#dynamicDataset").getCurrentItem();
let acc = item["out1_departing_nighttrain_accommodation_fromstation"].slice(36);
$w("#accommodationfromstation").value = acc;
// "#accommodationfromstation" is the ID of the dropdown, set correctly in the properties panel.

The result on screen looks like this (‘Acc.’ is the dropdown’s placeholder text).

On the same page, I also have a TextBox which is not expanding although I’m expanding it using code (here as well I’m sure the code is correct since the same code has worked perfectly before), so I suspect this could maybe have to do with a bug? Or am I missing something?

Anyone who can help me or maybe explain what I might be missing? Thanks!

What you want to do is perhaps to set the options of your dropdown instead of its value, right?

https://www.wix.com/velo/reference/$w/dropdown/options

Hi, thanks for answering. I definitely want to set the value, the options are already set from the editor. But I understand you might be wondering why I want to set the value, let me elaborate: the page is actually an input form which can be filled out (and in that case the dropdown value is just set by using the dropdown itself on screen), but the code above is used for a ‘load’ button, where the data that were previously put in are loaded from the database in order to e.g. be adapted (and hence it is the dropdown value that needs to be set here). But all I get is a validity error…

Never mind, I found the issue. There was a statement later in my code undoing the value setting that I forgot to delete… Pretty embarrassing right :speak_no_evil: Thanks anyway for trying to help!