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

[Sheet Workers] Repeating Sections and Checking a Checkbox Within

1515193208

Edited 1515193413
Hello all, I have a repeating section for a character's weapons with a roll button for each weapon. I would like to hide this button when the character becomes too encumbered. I can't seem to get the checkbox to check with the sheet worker. Here is the HTML for the section:  <fieldset> <input name="attr_itemname" type="text" placeholder="Name"> <input type="hidden" name="attr_test" value="0"/> <input type="checkbox" name="attr_toggle_double_encumbered_roll_weapon_damage" value="1"/> <button type='roll' name="roll_WeaponDamage" value="@{character_name} attacks with @{itemname} and rolls a [[1d4]]."></button> </fieldset> Sheet Worker Code for this specifically: getSectionIDs("repeating_weapons", function(rowIds) { var toggles = []; for(var i=0; i < rowIds.length; i++) { toggles.push("repeating_weapons_" + rowIds[i] + "_toggle_double_encumbered_roll_weapon_damage"); } getAttrs(toggles, function(values) {     setAttrs({ toggles: Number(1) }); }); });  Any help is appreciated, thank you!
1515196976
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
You are attempting to set an array to a value. the variable toggles is never cleared or set to something other than the array of repeating attribute names and would not be the values of the attributes from your getAttrs call. These attributes are contained in the object that you have named values in your code. What you want to do is this: getSectionIDs("repeating_weapons", function(rowIds) { var toggles = [], setObj = {} ; for(var i=0; i < rowIds.length; i++) { toggles.push("repeating_weapons_" + rowIds[i] + "_toggle_double_encumbered_roll_weapon_damage"); } getAttrs(toggles, function(values) { _.each(_.keys(values),(k)=>{ setObj[k]=1; });     setAttrs(setObj); }); }); Of course, for your final code, you'll need to put in the logic to determine if it should be checked or unchecked.
Thank you Scott, that solved it! I realize now the array is just returning the names of the attributes and not the key/value pairs. The method you showed turns each member of the the values associative array into the object using the keys and setting the value of that key to 1. Then the setAttrs method can use the object to do the work. Brilliant.
1515280885
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Happy Rolling