Module Input Data

Hi, I have a module (myModule1) which I have included in an app. I have a single input of type data (myInput). I can set the value of this input by inspecting the module and entering the value in the textfield provided. However I want to be able to set this input dynamically via a run script and I'm really struggling to do this.

I have tried various combinations of the following but it doesn't seem that I can change the input of a module dynamically.

e.g. myModule1.myInput = "Hello"

I'm fairly new to Retool but I have been through a number of forum posts but I'm not finding the answer to my particular problem.

Thanks for your help

Hi Simon,

For this functionality, you would need to set up an input that gets exposed to the application that will host your module. You can then connect that input to a component or query in the application. After this, then you can listen to any changes to that input from within the module.

For instance, you set an input called myInput in your module and initialize it as an empty array. When you add your module to the application, you edit the module in the basic field in the edit pane and point myInput at a component/query/state within the application (for example, helloState.value). You can now set up queries that run automatically when applicationState changes in your main application.

1 Like

@petermdamato Thanks for help, that worked perfectly.

1 Like

Hi Folks,

I'm also struggling with this. Am I correct in understanding that workaround suggested by Peter is to have some kind of state variable in the app holding a value that I can point the module input variables at? This feels frankly ridiculous! I have a state in my module called CreateorEdit, with which I control the UI based on whether the form is creating a new item or editing an existing one. I have a few other inputs too.

This workaround (for it is exactly that if I cannot programmatically set the input variables) would mean that for every input variable I have in the module, I'd have to set up some kind of state or query to hold a value for it outside the module to. This makes using modules far more clunky than simply dragging and dropping them in and setting their inputs. It means setting up matching states to hold a variable for each one. Am I doing something wrong?

Joshua

2 Likes

Hi Joshua,

Unfortunately, it sounds like you're on the right path! :disappointed:

We don't have a way to overwrite the module value directly using = or .setValue() - you need to change the underlying dynamic value.

In some cases, you may not need state; for example, if your input references a dropdown component, changing the selection will change the input:

Another example that doesn't require state is a JS query with dynamic data:

Since you can put Javascript inside of double curlies in Retool {{}}, some dynamic use cases could be solved in the input logic directly:

The temp state solution allows you to have the ability to overwrite the value, since temp state can be overwritten with .setValue()