Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Sheetworker to affect repeating section

I have a checkbox in a repeating section and I need a button outside the repeating section that will clear all the checkboxes within it. Is this even possible? If so, how? Here's the non-working code I've got: <fieldset class="repeating_gear"> <input type="checkbox" style="width:20px; height:20px;" name="attr_equip" value="1" /><span></span> <br /> </fieldset> <button type="action" type="number" name="act_clearload" >Clear</button> <script type="text/worker"> on('clicked:clearload', function() {     getAttrs([''], function(values) {         setAttrs({            "repeating_gear_equip": 0         });    }); }); </script>
1645820179

Edited 1645823159
GiGs
Pro
Sheet Author
API Scripter
It is possible, but you have to use getSectionIDs. This is a function that grabs an array of all the row ids in the section, and you then use it to iterate through the section and change the attribute on every row. If you just want to clear all checkboxes, and dont care what values the attribute had before, this is very easy.          on ( 'clicked:clearload' , function () {             getSectionIDs ( 'repeating_gear' , function ( id_array ) {                 const output = {};                 id_array . forEach ( id => {                     output [ `repeating_gear_ ${ id } _equip` ] = 0 ;                 });                 setAttrs ( output );            });         }); so the getSectionIDs at the start creates an array containing all the rows IDs (and it can be empty if there are no rows created yet). the forEach function works its way through that array, and creates a full name including the row id. In this string, `repeating_gear_${id}_equip` when you use backticks (` `)  you can include variables and other code inside ${ }, so this includes the variable for the row id. It creates an attribute with the proper name, and sets its value to zero, stored in the object called output . Then you just run setAttrs with output to save the values to the sheet.
Brilliant, cheers GiGs!