Assigning an updated event handler to a supplier control

Everything related to the development of modules in jamovi
Post Reply
becksetaylor
Posts: 4
Joined: Mon Jul 18, 2022 11:26 pm

Assigning an updated event handler to a supplier control

Post by becksetaylor »

I'm trying out making two analyses available within a module, and I see that I need to update the javascript file manually in order to make the second analysis work, but I don't see any explicit examples of what that would look like... the examples below from the tutorial make me feel like I'm missing a step! Partly because I'm not sure what I need to tell it to do!!

module.exports = {

// event handlers and functions are defined here

// this is an example of an event handler
view_loaded: function(ui, event) {
// do something
},

// this is another example of an event handler
ttestType_changed: function(ui, event) {
let value = this.calculateValue();
// do something
},

// this is an example of an auxiliary function
calculateValue: function() {
// do something
}
};

I'm just feeling my way around and would appreciate some guidance
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Assigning an updated event handler to a supplier control

Post by jonathon »

let me attend damo to this.

cheers
dropmann
Posts: 79
Joined: Thu Feb 02, 2017 10:26 am

Re: Assigning an updated event handler to a supplier control

Post by dropmann »

Hi, so what is it that you are trying to do that requires you to add javascript? Sometimes its easier to work through the exact problem to understand where you are getting stuck. I see the subject refers to wanting to assign an update event handler to a supplier. In the tutorial under the title 'Events' it describes how to add an event handler to a specific control event. So for a supplier control named bob the event handler for the 'updated' event would look like:

Code: Select all

bob_updated: function(ui, event) {
    let value = ui.bob.value();
    // do something in response to the event
}
When compiled, the compiler will attach this function to the event 'updated' of the control 'bob'.
becksetaylor
Posts: 4
Joined: Mon Jul 18, 2022 11:26 pm

Re: Assigning an updated event handler to a supplier control

Post by becksetaylor »

Hi! Thanks for your reply!

Ultimately when I build my module, I would like to have two analyses (and their within-analysis options) available to the user, so I am trying things out by extending on the tutorial at the moment in order to practice with simple(ish) things.

I successfully built the ttest from the tutorial, and am trying to add another analysis option to my module, I thought I would start by adding a simple linear regression and a plot. When I try to run the regression analysis I get the errors telling me I need to add an event handler. Of course all this may be entirely the wrong way to go about things!
It seems to me that what I'm trying to do is link up the correct analysis with that option on the UI. I also am not sure whether I should be making this change in the file associated with the first analysis or the new one that I've added.

I hope this makes sense! Thanks for taking the time to help a novice! :)

Cheers,
Rebecca
User avatar
jonathon
Posts: 2613
Joined: Fri Jan 27, 2017 10:04 am

Re: Assigning an updated event handler to a supplier control

Post by jonathon »

When I try to run the regression analysis I get the errors telling me I need to add an event handler.
could you provide a screenshot of this?

with thanks
dropmann
Posts: 79
Joined: Thu Feb 02, 2017 10:26 am

Re: Assigning an updated event handler to a supplier control

Post by dropmann »

Ok, i think i may understand what is happening. So there are two supplier controls. 'Supplier' which is a generic supplier of anything. There is also a 'VariableSupplier' which has a back-end to handle all variable populating and updating. If you are using the 'Supplier' then it needs the event handler attached so that it can be manually populated/updated with content. The 'VariableSupplier' does this all automatically, unless you set the 'populate: manual', which will cause this error to be thrown as well. Hope that helps.
dropmann
Posts: 79
Joined: Thu Feb 02, 2017 10:26 am

Re: Assigning an updated event handler to a supplier control

Post by dropmann »

Information regarding the finer details of suppliers is not yet in the tutorials and explains how you couldn't figure it out.
becksetaylor
Posts: 4
Joined: Mon Jul 18, 2022 11:26 pm

Re: Assigning an updated event handler to a supplier control

Post by becksetaylor »

jonathon wrote:
When I try to run the regression analysis I get the errors telling me I need to add an event handler.
could you provide a screenshot of this?

with thanks
Here you go!
Error message.png
Error message.png (137.44 KiB) Viewed 2881 times
becksetaylor
Posts: 4
Joined: Mon Jul 18, 2022 11:26 pm

Re: Assigning an updated event handler to a supplier control

Post by becksetaylor »

dropmann wrote:Ok, i think i may understand what is happening. So there are two supplier controls. 'Supplier' which is a generic supplier of anything. There is also a 'VariableSupplier' which has a back-end to handle all variable populating and updating. If you are using the 'Supplier' then it needs the event handler attached so that it can be manually populated/updated with content. The 'VariableSupplier' does this all automatically, unless you set the 'populate: manual', which will cause this error to be thrown as well. Hope that helps.
Yes, I think this is right, and as you say below, there's no information added yet on how to do it. I've never tried to do something like this before, so don't have any experience to fall back on to figure it out! :)
Post Reply