How to set the initial value in a dropdown with dynamic options

Hello,

In my app I am displaying a “Region”. Here the user can update the name and the HQ location of that region. In Xano I have a database table of “companies” and a “regions” table. Each region has a company set as the HQ location.
In WeWeb I have a dropdown with a dynamic list of options coming from a database table “companies” in Xano.

Now I would like to set the initial value of this dropdown to the company that is set as the HQ location of this Region.

I’ve tried 100 different things but I couldn’t figure this out. Any advice on how to set the initial value correctly if you have a dynamic dropdown with data coming from Xano?

Thank you in advance!

In the field initial value you put the same id, that matches your desired preselected item, from the items that is plugged into the dynamic options. (Bwcause your ids are the values)

I think what you need to do, is do “On Change”“Change variable value - to the event value” (of your premade variable)Bind the variable to the init value

1 Like

Thank you, that solves my problem!

I do see a small error message in the editor as it’s expecting a string and not a number.

Although it’s not blocking anything, is there a way to get rid of this error?

I wouldn’t worry about it. For now, I don’t think there is a simple and fast fix.

1 Like

your value it’s a number, the error says that is expecting a string. Eventually the value will be implicitly converted to string. You can add an explicit conversion, for example by wrapping it like this String(YourValue)

I think that wouldn’t match the 0 in the select [‘id’] value, would it? I’m not sure whether it is a string at the end or nay. I remember that kanban had a problem with this, when you set “0” to the stack and 0 to the identifier.

right, that would require to make the value in the options a string as well