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

Turn on/off some class in a repeating section

Well, i'm going into hard issues, but I assume, simple resolution when you know the syntax. This is a script I use in another section and it work perfectly, I wanted to do it, now, in a repeating section, and its gone wild :         < script type = "text/worker" >             //SCRIPT DISPLAY OR NOT EDIT DAMAGE ON ACTIONS SECTIONS                             on('sheet:opened change:actions-damagecheckbox', function (eventInfo) {                 console.log(eventInfo);                  getAttrs(['actions-damagecheckbox'], function (values) {                   const DamageEditable = parseInt(values['actions-damagecheckbox']) || 0;                   console.log('DamageEditable', DamageEditable);                   let button = $20('.sheet-editable-damage');                   if (DamageEditable === 1) {                     button.addClass('edit_ok');                     button.removeClass('edit_none');                   } else {                     button.addClass('edit_none');                         button.removeClass('edit_ok');                   }                 });               });             </ script > So I've try things and the last thing I've try was... that,  but nothing seems to work right and my brain will explode. What did I miss ? :/             < script type = "text/worker" >                 on('sheet:opened change:repeating_actions:actions-damagecheckbox remove:repeating_actions', function () {                     console.log(eventInfo);                     getSectionIDs('repeating_actions', function (ids) {                     ids.forEach(function (id) {                       getAttrs(['repeating_actions_${id}_actions-damagecheckbox'], function (values) {                         const IsDamageEditable = parseInt(values['repeating_actions_${id}_actions-damagecheckbox']) || 0;                         console.log('Damage Box', repeating_actions_${id}_actions-damagecheckbox);                         let button = $20('#repeating_actions_${id}.sheet-editable-damage');                         if (IsDamageEditable === 1) {                         button.addClass('edit_ok');                         button.removeClass('edit_none');                         } else {                         button.addClass('edit_none');                         button.removeClass('edit_ok');                         }                       });                     });                   });                 });               </ script >
1681396803

Edited 1681442489
GiGs
Pro
Sheet Author
API Scripter
I wouldnt put getAttrs inside a loop the way you have there, but that's not the issue. is the problem one of incorrect syntax? Shouldn't this: let button = $20('#repeating_actions_${id}.sheet-editable-damage'); be this: let button = $20('#repeating_actions_${id}_sheet-editable-damage'); Also, should the hash mark be there? That's for ids, not classes. I haven't done anything with Roll20's jquery yet, so who knows :) Maybe it's not going to be possible to figure this out without knowing the structure of your sheet. It looks like you are trying to change every row of a repeating section. Wont those changes be forgotten when the sheet is closed and relopened? I'm just wondering why you are doing this and what you are going for. PS: you've put this in the Mod forum, but it seems to be a sheet worker question and therefore should be in the character sheet forum. Have I misunderstood?
Is it, certainly, sorry... ! Sometime doing fast, doing wrong :/ I always try to avoid problems by contourning, I'll certainly do that there too ! The html was looking like that, wanted to hide all the . sheet-editable-damage  when its 0, show when its 1 : But got hard time to try to explain my code that every row need to be independant. :X < fieldset class = "repeating_actions" >     < select class = "sheet-checkbox" name = "attr_actions-damagecheckbox" id = "damagecheckbox" >         < option class = "sheet-no" selected value = "0" >✗</ option >         < option class = "sheet-yes" value = "1" >✓</ option >     </ select >     < input class = "sheet-actions sheet-editable-damage" type = "text" value = "0" name = "attr_actions-damage1" >     < input class = "sheet-actions sheet-editable-damage" type = "text" value = "0" name = "attr_actions-damage2" >     < input class = "sheet-actions sheet-editable-damage" type = "text" value = "0" name = "attr_actions-damage3" >     < input class = "sheet-actions sheet-editable-damage" type = "text" value = "0" name = "attr_actions-damagecrit" > </fieldset>
1681442957

Edited 1681443146
GiGs
Pro
Sheet Author
API Scripter
I havent done any coding attempts yet, but I notice this in the wiki page : The jQuery functions as they are currently implemented have several limitations: The contents of individual repeating items can't be targeted or reacted to That reads to me that it doesnt work with repeating sections yet (or maybe the trigger item like your checbox can't be inside a repeating section?).
1681447307
John D.
Pro
Sheet Author
I think that limitation is when using jQuery for triggers/events.  Instead, you can use the normal sheet worker events for reacting to changes in the sheet, then jQuery to affect classes.  However, you will affect all classes of the same name, even across repeating sections (I've switched to this method for applying color themes in my sheet).  Bear in mind, the class name must be unique if you want to target it specifically, and repeating sections do present a problem but I estimate you could overcome it. 
1681485322
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
The problem here is that the row id that is stored on the repitem element is fully cased. However, the rowID that we can access via sheetworker is all lowercase. Additionally, the Roll20 implementation of jquery does not accept the case insensitive tag on property selectors. This means that there's no way to properly select a row using the default Roll20 fieldset controls. There is a work around, but it is a little complex. You can hide the default "add" button for the fieldset and replace it with an action button to trigger a sheetworker that will add the row, and store the true rowID of the row in an attribute on the row. Then you can get the full row ID with true casing from that attribute, and use that to target the specific row you want.