Raise an on change event in a module

I created a module with one select component. It loads up from my DB, it has 3 inputs and 2 outputs. So far everything works as planned.

However when I select something in the select component I want it to trigger something. But there is no way to add an event to that module in the inspect tool.

How can I Trigger or Raise an event onChange when the user selects a value from the select component when it's a module?

Thanks for your support.

More context needed but you would have to account for the input in the module itself based on urlparams or something similar to then have that component fire an event. Since modules are self contained the event needs to be defined within the module itself

Hi Stephen!

There aren't any event handlers at the module level, just individual queries and components.

I think the closest thing to what you want is specifying an input of a "Query" type:

If you do that, you'll have a dropdown in the parent app to select an individual query. That will be passed into the module (any input1.data properties, etc) and any triggers targeting the input inside of the module will re-run the specified query in the parent app.

@alex-w curious and want to learn more. Why couldn’t the main app set a urlparam for the module to read in and then run a query. I have done this before.

Using an input query lets you pass in a larger amount of data in a more convenient way that a massive URL string, and it lets you trigger the input query to re-run from inside of the module's logic.

I guess what I am asking is that if a module has an input for a parameter value couldn’t you just run the query in the module based on that parameter and then dump it into the main app? I’m not suggesting an entire url just the param. So let’s say you have module and the input is x and the value of x is set to be the value of the param only fort the query in the module and then the module should run it and put the response back to main app where needed. Am I missing something? It’s the event query on the parent that’s the issue? If so, it should be a contender to be a feature but maybe it isn’t?

1 Like

I agree that it is generally best practice for modules for be mostly self contained, with inputs being passed in to reusable logic inside the module. Having a large amount the logic outside of the module is difficult to maintain and configure as the parent apps get updated.

Having an input/trigger output query is nice in some scenarios, like being able to trigger actions in the parent app or run JS code there without having to watch an output value from the module as a "When Inputs change" query trigger. It also might be helpful if you have a single query, say a getUsers query that you want to pass the inputs into 4 separate user editing modules in a single app. If you wanted to refresh the query in one of those modules then that could also update the values for the others at the same time since they all share the same reference instead of 4 separately run getUsers queries written in each module.