Hi,
So I’ve got a clone matrix with 10 toggle widgets. I would like to loop over them to get each widgets value and use them in a javascript to trigger other widget values in my template. I’ve tried to search for the answer in the community but with no luck. I’m not an experienced programmer, so if anybody can point me in the right direction I would be very glad.
Thanks in advance!
Erik
PS, my question is based on the JSON file in the attachment
clone-matrix.json (2.0 KB)
Hi, I’m off for a few weeks so I wont be able to get back to you before the end of the month, sorry.
1 Like
A little bug prevented this to be easily solved, it’s just been fixed (in git sources, to be released soon). With the fixed version, you’ll be able to simply use @{matrix_1}
in a JS{{ }}
block as you would with any other widget:
For example, you’d create a script widget with value
set to @{matrix_1}
and script
set as follows:
JS{{
// "value" is an array containing the matrix' children's values
// something like [0, 0, 0, 1, 0, 1, ...]
var n_active = value.filter(x=>x==1).length
set("input_2", n_active)
}}
This would send the number of active toggle to widget “input_2
”, whenever a widget updates in the matrix.
Here is a session adapted from yours that demonstrates this, you can import it in the online demo to try it, until the fixed release comes.
References:
Hi Jean-emmanuel,
Thank you for the update! I will go from there.
regards,
Erik