To do this you will need to create an event.js file. The tutorial support for this is lacking currently but will be improved soon. I'll layout a quick summary below. I'll use an example analysis called ‘fred’.
In this example I will create a system where textbox will declare the state of a checkbox by saying ‘Checkbox ON’ or ‘Checkbox OFF’. The textbox will be call textbox1 and the checkbox will be called checkbox1. I am making the assumption that the fred.a.yaml and the fred.u.yaml have already been setup appropriately to create and display these controls in the options panel when the fred analysis is run.
To create this system, we will need to attach some javascript code to some events. In this case the events will be the ‘change’ event for the checkbox and the ‘update’ event for the analysis.
In the jamovi directory of your module there should be a directory called ‘js’ (if not create it). It’s in this directory that the event.js files live for the module. It is good to have one per analysis. For this example, I will create a file called fred.events.js. This file will contain the javascript that is to be executed in response to specific events that will occur in this analysis.
The content of the file would look like this:
Code: Select all
const events = {
// in here is where the event functions go
update: function(ui) {
updateTextbox1(ui);
},
onChange_checkbox1: function(ui) {
updateTextbox1(ui);
}
}
// out here we can have support functions if necessary
let updateTextbox1 = function(ui, context) {
let value = ui.checkbox1.value();
if (value)
ui.textbox1.setValue('Checkbox ON');
else
ui.textbox1.setValue('Checkbox OFF');
};
module.exports = events;
The ‘update’ function is to be called when the ‘fred’ analysis is selected. It initialises the state of the controls.
The ‘onChange_checkbox1’ function is to be called when the value of the control is changed. In the case of ‘checkbox1’, the value will change between ‘true’ and ‘false’ when checked or unchecked.
Next, we will need to attach these event functions to the controls and analysis so that they will listen for the events to occur. To do this we will need to modify our ‘fred.u.yaml’ file.
At the top of the u.yaml file, at the analysis level, we would add an ‘events’ group (if it doesn’t already exist). Inside the events group we create a property called ‘update’ and make its value the path to our newly created ‘update’ function. The path follows this pattern: ‘./filename::function’.
Code: Select all
name: fred
title: FRED
jus: '2.0'
compilerMode: tame
events:
update: './fred.events::update'
Then, we can do the same to the checkbox description and link to the ‘onChange_checkbox1’ function that we created earlier.
Code: Select all
- type: CheckBox
name: checkbox1
events:
change: './fred.events::onChange_checkbox1'
Below is a list of the different control events that can be attached to:
Analysis:
- update: Is fired whenever an analysis is selected.
All controls:
- change: Is fired when the value of the control is changed.
- changing: Is fired before the value of the control is changed.
ListBox:
- listItemAdded: Is fired when a control is added to a list box.
- listItemRemoved: Is fired when a control is removed from a list box.
If we then create and install the module we should be in business. I hope this is helpful. I appreciate that it does not address your exact situation but should provide a knowledge base to move forward.
Please let me know if something doesn't work, just in case i have forgotten something.