Setting Default Value on Mobile Select Component

I have a form which associates a database record with a particular county. I have managed to fill the select list with countries from the database. My problem is how do I select the default value for the select list for a current record. I have tried the following but this does not seem to work
image

The country_id is a valid id from the countries list but I want to display the corresponding country_name.

Can anyone advise how to set the current value for the list as using the default value as shown is not working.

Thanks

Default value should exist in the values list. Can you share more about what getFBLeague.data.Country_id, getCountries.data.id and getCountries.data.Country_Name look like at runtime?

I can confirm {{getFBLeague.data.Country_id}} is a valid item in the values list of {{getCountries.data.id}}

I'm very new to this development environment. Is there a way of interrogating component values at runtime to prove this?

@mkhalford You might want to try {{getFBLeague.data[0].Country_id}}, assuming that index 0 is the value you want to be your default value. Country_id would then show the value of the property Country_id

Your recommendation does not work.
image

I have however tried {{getFBLeague.data.Country_id[0]}} but still to no avail.

Mike

What kind of data is getFBLeague returning? An array of objects with various properties?
Can you post an example?

getFBLeague returns a result of parameterized SQL query. Will only ever return one row.

select * from FB_League WHERE id={{state2.value}}
image

Query returns correct data. If put results into text or numeric input components everything is correct. Its just the setting of the default value for the select component where the issue is.

I have even tried saving the Country ID to a state value before loading screen but still am unable to get the select component to show any value.

This is how its working for me. Getting a list of branches for a MySQL db.
The default value has to be the same as the values, in my case it is a string of two characters (NL)

@mkhalford here's a simple demonstration app for Select's default value. One issue you may be running into is that the default value needs to be a string, even if the values are numbers.

select default value demo (1).json (5.8 KB)

Thanks bca.

After further investigation you are correct. The key values in question are integers not strings.

Might have to look at a different solution as majority of values that we will need to use for lookups etc. are numbers.

With my limited java skills I tried stringing value using {{ lstFBLeagues.data[0].Country_id.toString() }} but still no luck. If I change default value to a hard coded value like {{"1"}} it works fine.

Not sure how we can get round this.

Isn't it possible to set the default value based on League_Name? Or does that contain duplicates?

League_Name is no good. I'm trying to set the default value for the country associated with the league.

I have a list of countries (id (int), country_name (nvarchar)) and the selected country id is held in the league record table (id (int), league_name (nvarchar), country_id (int)).

All I need to do is when displaying a league record set the select component to be the corresponding country_name based on the country_id of the league.

Stringing the country_id would be the answer but all attempts to do this are failing. As stated earlier in conversation forcing a string example {{"2"}} works.

@mkhalford do you mind starting an email thread with me at braden AT retool dot com? I can probably figure out what's going on in a live debugging call.

email sent.

All sorted. With the help of a retool engineer. Was indeed issue of strings and integers. Stringing the default value resolved the issue.

{{ String(lstFBLeagues.data[0].Country_id) }}

1 Like