Form data changing depending on table being empty and javascript wrapper concept

Hi everyone,

I am rather new to retool and I am stuck with a problem and possibly two questions:

  1. I want to prefill the form component with data from a filtered table (this works fine). But this table can be empty and in that case I want to prefill some of the form input fields with custom values (e.g. current date, a default value, a calculated value and so on). What would be the best way to achieve that?

My initial thoughts were to do that in the "data source" property of the form component or to use a query and to "setData", but in both cases I got stuck with question 2 --> see below

  1. I am not sure whether I understood the {{}}-wrapper concept for javascript. I used

in the "Data Source" field of the form successfully. But this:

let x = table1.selectedRow; = 23 //does not work even without this line
return x

does not work. I am very hopeful that someone can help me understanding the concept a bit better...

I believe it's supposed to be {{}}.

Some workarounds to explore:

  1. Perhaps you can set up a Temporary state where you can store an Object with your custom values, then use something like {{ ? : temporaryState.value }} for your form's data source.

  2. If your form fields are static anyway, you can just set a Default value for it.


With the new table {{ table1.selectedRow }} should work fine without adding .data! Transformers parse singular JavaScript expressions, so multiline JavaScript doesn't work particularly well. For your case, you might try something like {{ {...table1.selectedRow, id: 23} }} or {{ Object.assign(table1.selectedRow, {id: 23}) }}. If you want to use multiline JavaScript I would suggest using a standalone transformer instead.

Fun fact: immediately invoked function expressions work too but they aren't a great design pattern within Retool as it can get pretty messy :sweat_smile: