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

Checkbox to toggle a repeating attribute checkbox

1560661354

Edited 1560698445
vÍnce
Pro
Sheet Author
es anyone have a sheetworker example (or even point out a sheet with this feature that I might "study") they could share that uses a checkbox to toggle a repeating attribute checkbox?  Think of a column header checkbox (attr_show-toggle) that checks/un-checks every row in that column. I want to toggle a given repeating attribute (attr_showinmenu) for all existing repeating rows within the repeating section (repeating_ability). example; Any help appreciated.
1560665308

Edited 1560704835
GiGs
Pro
Sheet Author
API Scripter
Is it meant to set all the showinmenu boxes to equal the show-toggle value? If so, try this: on("change:show-toggle", function() {     getSectionIDs("repeating_ability", function(idArray) { const fieldNames = idArray.map(id => `repeating_ability_${id}_showinmenu`); //build an array of showinmenu attribute names getAttrs(['show-toggle'], function(values) { const toggle = +values['show-toggle']||0; const settings = {}; // initialise an object for the setAttrs function fieldNames.forEach( field => { // loop through the showinmenus array settings[field]= toggle; // assign the toggle value to each row's attribute }); setAttrs(settings); });     }); }); this assumes show-toggle value will be 0 for unchecked, and 1 for checked.
1560671697
GiGs
Pro
Sheet Author
API Scripter
Here's a slightly more compact version, both do the same thing. on("change:show-toggle", function() { getSectionIDs("repeating_ability", function(idArray) { const fieldNames = idArray.map(id => `repeating_ability_${id}_showinmenu`); getAttrs(['show-toggle'], function(values) { const toggle = +values['show-toggle']||0; const settings = fieldNames.reduce((obj, item) => (obj[item] = toggle, obj) ,{}); setAttrs(settings); }); }); });
1560695547

Edited 1560698610
vÍnce
Pro
Sheet Author
GiGs said: this assumes show-toggle value will be 0 for unchecked, and 1 for checked. Thank you for an unexpected father's day gift GiGs. ;-)  Of course  I'm lying about the unexpected part... I had a feeling you might respond to my pleas for help.  Adding a column header toggle such as this might be beneficial to other sheet authors as well. I'll try and integrate your code and report back.  Thanks again. Update : Works perfectly! Checked Unchecked
1560704882
GiGs
Pro
Sheet Author
API Scripter
You're welcome! (there was a slight error in the first script of course, haha, I just corrected it.) Happy Father's Day!
1560706324

Edited 1560706679
vÍnce
Pro
Sheet Author
Thanks GiGs. Quick question; is there something else that needs to be included so that the repeating attribute change triggers other events?  The column toggle works as expected (all showinmenu attributes/row check/un-check ), but I noticed that other sheet events that listen to change:repeating_ability:showinmenu  aren't being triggered. Specifically, chat menus get recalculated when toggling the showinmenu checkbox individually, but they are not being recalculated when using the showinmenu_all_abilities. Current code (note: I updated the attribute name from show-toggle to showinmenu_all_abilities) on("change:showinmenu_all_abilities", function() { getSectionIDs("repeating_ability", function(idArray) { const fieldNames = idArray.map(id => `repeating_ability_${id}_showinmenu`); getAttrs(['showinmenu_all_abilities'], function(values) { const toggle = +values['showinmenu_all_abilities']||0; const settings = fieldNames.reduce((obj, item) => (obj[item] = toggle, obj) ,{}); setAttrs(settings); }); }); });
1560706869

Edited 1560707105
GiGs
Pro
Sheet Author
API Scripter
That's interesting, I don't know why it wouldnt be triggered by that.  I've built many sheet workers that rely on those kind of cascading effects. This function is no different from any other in that respect - all that's relevant for that is the setAttrs call. I'll do some digging to see if I can replicate that, but in the meantime, a workaround would be to also add change:showinmenu_all_abilities  to any sheet worker that has change:showinmenu. PS: can you post the code of one of those other workers that isnt firing?
1560711518
GiGs
Pro
Sheet Author
API Scripter
Just tested with some code and a test repeating section, and it seems to be working fine. Can you post the html for your repeating section, and the sheet workers that arent firing properly?
1560714004

Edited 1560714109
vÍnce
Pro
Sheet Author
html for ability section:&nbsp; <a href="https://gist.github.com/vince-roll20/561fb5d9ac8259b7f4dc2c0800664896" rel="nofollow">https://gist.github.com/vince-roll20/561fb5d9ac8259b7f4dc2c0800664896</a> sheetworker for ability:&nbsp; <a href="https://gist.github.com/vince-roll20/20ae0e0a18ab13e790400747a721286e" rel="nofollow">https://gist.github.com/vince-roll20/20ae0e0a18ab13e790400747a721286e</a> 90% of this is probably not needed, but the pf sheet breaks out various sections into modules that later must be compiled (npm run ...) before generating an index.htm file.&nbsp; Great for programmers, but this can be rather confusing for non-programmers. ;-(
1560714759
GiGs
Pro
Sheet Author
API Scripter
I think you'll need to get whoever wrote that sheet worker code to find the problem here. That's way too complex for me to deal with at the moment. There are some surprises in the code for me. Can you use imports in roll20 sheet workers? And if so, how do you test they are working in a custom sheet?
1560715668
vÍnce
Pro
Sheet Author
Lol.&nbsp; Welcome to my world GiGs.&nbsp; Chris B. created 99% of the 13K+ lines of sheetworker code for the PF sheet over a 2+ year period but has since moved on from roll20 early last year...&nbsp; While I've been along for the ride, once the js stuff was added I've been rather limited(pure ignorance of js) on what I can and can't do on the sheet.&nbsp; We work with the code in it's separate modules(index, and about 15 separate sheet worker modules) within VSC &nbsp;(which recognizes import/export of the various functions) and have to use npm to compile for roll20.&nbsp; I'll keep fooling around.&nbsp; I know there has to be some function that is listening to the repeating showinmenu attribute and thus firing a recalc of the chat menu to show the appropriate menu items.&nbsp; I appreciate your help.
1560717875

Edited 1560718022
vÍnce
Pro
Sheet Author
I think I figured it out... I had to add an import line at the top of the PFAbility.js module import * as PFAbility from './PFAbility'; and then I added a line to call the recalculate function after checking/un-checking the showinmenu_all_abilities attribute. // toggles the chat menu Show option for all repeating abilities on("change:showinmenu_all_abilities", function() { getSectionIDs("repeating_ability", function(idArray) { const fieldNames = idArray.map(id =&gt; `repeating_ability_${id}_showinmenu`); getAttrs(['showinmenu_all_abilities'], function(values) { const toggle = +values['showinmenu_all_abilities']||0; const settings = fieldNames.reduce((obj, item) =&gt; (obj[item] = toggle, obj) ,{}); setAttrs(settings); PFAbility.recalculate(); }); }); }); Thank you for the help GiGs.&nbsp; No way I would have gotten here without it.&nbsp; ;-)
1560724437
GiGs
Pro
Sheet Author
API Scripter
Congrats! I couldnt have got there, since I have no way of knowing what those external functions do.
1560724537
GiGs
Pro
Sheet Author
API Scripter
Vince said: Lol.&nbsp; Welcome to my world GiGs.&nbsp; Chris B. created 99% of the 13K+ lines of sheetworker code for the PF sheet over a 2+ year period but has since moved on from roll20 early last year...&nbsp; While I've been along for the ride, once the js stuff was added I've been rather limited(pure ignorance of js) on what I can and can't do on the sheet.&nbsp; We work with the code in it's separate modules(index, and about 15 separate sheet worker modules) within VSC &nbsp;(which recognizes import/export of the various functions) and have to use npm to compile for roll20.&nbsp; I'll keep fooling around.&nbsp; I know there has to be some function that is listening to the repeating showinmenu attribute and thus firing a recalc of the chat menu to show the appropriate menu items.&nbsp; I appreciate your help. Ah that explains it. so the imports aren't in the actual roll20 sheet once it's compiled.