Why isn't my form Default setting working?

Hi, I am working on my first Retool project. I have a form that with a number of fields on it, and I would like to have some of those fields default to a value that is selected from a table based upon another field setting. I have this working for the field labeled "Division", but it will not work for the field labeled "Height" for some reason.

The query I am using is returning 2 fields. It looks like this:

Select "Default_Division", "Default_Height" From "Dogs"
Where Call_Name = {{new_call_name.value}}

I have the Default for the Height field set to:
{{ Dog_Defaults.data.Default_Height[0] }}
This is not working.

I have the Default for the Division field set to:
{{ Dog_Defaults.data.Default_Division[0] }}
This DOES work.

Can someone tell me what is causing this problem and how to resolve it?

Hi there @Larrynewby, welcome to the forum and to retool!

My first guess is that you don't have defined options for your select component. When the default value is a text string it may automatically use it both as label and value, but if it is an integer it may not do it. You may actually want to change that component to a number component, rather than a select one. That should definitely do the trick.

Thanks very much for your suggestion @MiguelOrtiz, but how would I do that?

Hi @Larrynewby,

So, there are several things I can see you could do to make your form more efficient.

From a query perspective:

  • In the Transform Results section of your query you can add the helper return formatDataAsArray(data) This will make your data more readable. To see how that changes, just right click > state on your query and you'll see the resutls before and after

From a form pespective:

  • Add Dog_Defaults.data as your data source by selecting your form component . What this will do is ready the data and assign values to matching keys. So if your data has a Height key, and your form has a component with data key field (see below) as Height, it will set up the value automatically.
  • Within each component, there is a form data key field, where you can put the key, this will then automatically set the default value of yoru form whenever there is data available. For example in your division component you can write Default_Division, in height you can write Default_Height
    -And to reply directly to your question. Simply delete the select component and add a new number component dragging it from the UI panel. Once you add it, you can change the label and set the data key field.

Hope this helps!