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

Custom Sheet - setAttrs value to Repeating Section

So I've been working on my own custom sheet for a few weeks now, and despite having a some experience with HTML and CSS, I'm strugling some with the sheetwork part. I was wondering if its possible to apply a value to all repeating attributes when a attribute from outside the repeating fieldset changes. To be more specific, I want to make that when a checkbox in the sheet is unchecked, it applies the value "0" to all chosen repeating inputs. Is there a way to maybe collect all existing IDs and apply this value to each of them? This is how my code looks so far: const prepedit = ["repeating_languages"] prepedit.forEach(function (prepedit) { on("change:edit_toggle sheet:opened", function(){ getAttrs(["edit_toggle"], function (repclosewindow){ let editvalue = String(repclosewindow.edit_toggle); if(editvalue === "0"){ setAttrs({ [prepedit+"_showcheck"]: 0}) }; }); }); }); And by the error the console is giving me (see below), i suppose i'd have to apply the value to each ID individually, and loop it until all have been changed. Though I have no idea how to do that. SHEET WORKER ERROR: You attempted to set an attribute beginning with 'repeating_' but did not include a Row ID or Attribute Name in repeating_languages_showcheck
1613783910

Edited 1613800080
GiGs
Pro
Sheet Author
API Scripter
ARNOLDO B. said: And by the error the console is giving me (see below), i suppose i'd have to apply the value to each ID individually, and loop it until all have been changed. Though I have no idea how to do that. You're correct that this is what you need to do. The getSectionIDs function exists for this purpose. Here's code based on yours above that should do the trick. This assumes you'll be doing this to multiple repeating sections (adding more names to the prepedit array later). It can be made a bit simpler if that's not the case. const   prepedit  = [ 'repeating_languages' ]; on ( 'change:edit_toggle sheet:opened' ,  function (){       getAttrs ([ 'edit_toggle' ],  function ( values ) {          const   edit  =  values . edit_toggle ;          if ( edit  ===  "0" ) {              prepedit . forEach ( function  ( section ) {                  getSectionIDs ( section ,  function ( idarray ) {                      const   output  = {};                      idarray . forEach ( function ( id ) {                          output [ section  +  '_'  +  id  +  '_showcheck' ] =  0 ;                     });                      setAttrs ( output );                 });             });         }     }); });
Mmm, I tried this code but it didnt work. It seems fine to me, can't quite tell what is wrong.
1613795194

Edited 1613799995
GiGs
Pro
Sheet Author
API Scripter
can you post the html for the repeating languages section and the edit_toggle input?
1613800021

Edited 1613800119
GiGs
Pro
Sheet Author
API Scripter
My code had an error in it (related to the way javascript handles zeroes). I have corrected it.
Yup, now it worked like a charm! I was digging through the html and css to get all related code and just saw the update. I indeed intend to apply it to other repeating rows so the  const   prepedit  will come in handy. Thanks a lot for the help :D
1613810680
GiGs
Pro
Sheet Author
API Scripter
You're welcome :)