Expose events/action from a module

Greetings,

I decided to try out Modules today with an Event selector (using a drop-down selector) used in many of our apps. Is there a way to expose an onSelected event from a module so it can call/run a javascript query in the application the module is being used in? I hope that was clear.

Thank you,
Brett

Hey Brett,

I think you should be able to use a "Query input" to your module, so that you will be able to run a query from your app based on changes in the module:



Then in the app, you would just need to specify the input query in the module inspector panel:


1 Like

Huh, thats pretty interesting. I'll have to give it a go

👍 Let me know if you run into any other questions/diffficulties!

So I am not sure if I used this since asking, but I had another need to today and as you laid this out I am able to trigger a query in my application from the module's event.

For future and others' reference:

  • In the module I setup and input called OnChangeQuery with type query and provided a description for the input.
  • When using the module in the application there is a new value in the basic section, yep, OnChangeQuery. I set this value to the query I want run on change value.

Works as expected. The query is run when the selected value is changed.

Thank you @mark The instruction I needed :slight_smile:

1 Like

I think this might help me do what I want, but it doesn't seem to be working.
I want to have a module that contains a form with some input fields. When the submit button is pressed, I want it to run a query that uses the input fields in a rest call. I then want to put the results in the output. An app using the module would then populate a JsonEditor with the results.
I haven't gotten it to work. My module works, and I added it to an app, created a Javascript query that simply runs "return myModule.output1;" and assign that query as the input query for the module. The query is invoked but seems to return nothing (empty string).

My bad, I didn't quite have things wired together properly. Works great!

OK, I do have another challenge - After setting some fields in a form in my module and using the above technique to emulate an event, I later on want to be able to clear the text fields inside the module from elsewhere in the application it is used in.

You will likely need to create an input to the module which can be used to trigger a JS query inside the module which calls form.clear(). Then in the app, you would be able to pass a value into that input to trigger the form clear. Let meknow if you have any difficulties getting that implemented!

How would I trigger a JS Query on change of the input variable?

I am not sure I am following, what do you mean by input variable?

Unfortunately, JS queries do not support "Run on inputs change". To work around this, I often will use a "query JSON with SQL" query that does something like

select * from {{input.value}}

then have that query trigger the JS query I want to have run when the input changes. I believe that we do have plans to allow running JS queries on input change in the future, but at this time, I don't have a timeline for that

Above, @mark suggested I "create an input to the module which can be used to trigger a JS query inside the module". I don't see a way to provide an input externally to the Module that causes the module to trigger a JS Query.

Ahh.. I see he has responded. That makes sense.

Better ability to affect Module internals and have module internal events propagate out would sure be nice.

Oh, sorry, I misunderstood. You can create an input in the upper left of the editor, and then pass a value into the module from your parent app. For example:

Module editor:

Using the module in an app:

2 Likes

Yeah, I get it now - it's the "query JSON with SQL step" that that I was not clear on.

Ah gotcha. :+1: Let me know if you run into any issues setting this up!