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 .
×

Problem creating repeating section with sheetworker

I'm trying to create a custom sheet, and I've run into a strange error with my javascript to add a repeating section item, and I'm not sure if I'm doing something wrong, or it's a Roll20 bug.  What's happening is that when I use a sheetworker to add a simple repeating section item with two variables, it gets the repitembroken class applied.  And I can't see anything wrong with the html when I look at it with the inspector (but I'm new to this). After chasing a bunch of red herrings, I've simplified my code down to the attached.  When I create the first item using the "+Add" button ("manual") it works.  When I use the blue button to add one using a handler, it fails ("dummy1"). Help! I'm working to setup a pastebin account so I can post the full css/html, but they're having a slow day apparently. Here's the html and the javascript that adds the item when the button is clicked. <div class="sheetbox"><!-- The Character Sheet Wrapper (goes around entire sheet) --> <header> <h1 >Test Sheet</h1> </header> <div><!-- main portion of sheet --> <div class="tab-flex-container"> <div class="flex-vert flex-wrap attacks-box"> <label>Attacks:</label> <button type="action" name="act_addattack" class="attack-link-control" value=""> <div class="attack-button-text-color attack-link-control-text-center ui-icons">A</div> </button> <div class="flex-horiz attacks-row"> <label>Weapon</label> <label>mod</label> </div> <fieldset class="repeating_attacks"> <div class="flex-horiz attacks-row"> <label><input type="text" name="attr_atkname" class="attack-info text-long" value=""></label> <label><input type="text" name="attr_atkmod" class="attack-info text-short" value="" ></label> </div> </fieldset> </div><!-- attacks --> </div><!-- end container --> </div><!-- end main --> <footer class="section footer"> <!-- was <footer> --> <div class="footer-text">Test sheet footer</div> </footer> <script type="text/worker"> const createUniqueRowID = row_ids => { row_ids = Array.ids ? row_ids : []; let generated; while (!generated || row_ids.includes(generated)) { generated = generateRowID().toLowerCase(); } row_ids.push(generated); console.log('createUniqueRowID: generated "' + generated + '".'); return generated; }; const sectionName = (section, id, field) => `${section.startsWith('repeating_') ? section : `repeating_${section}`}_${id}_${field}`; // button handler on('clicked:addattack', (e) => { console.log('button clicked.'); addAttack(); }); const addAttack = () => { let attackItem = {}; let section = 'attacks'; let attackRowID = createUniqueRowID(); let fieldName = sectionName(section, attackRowID, 'atkname'); attackItem[fieldName] = 'dummy1'; fieldName = sectionName(section, attackRowID, 'atkmod'); attackItem[fieldName] = '0'; console.log('addAttack: calling setAttrs.'); log(attackItem); setAttrs(attackItem, {silent: true}, () => { console.log('addAttackForItem: add complete.'); }); // setAttrs }; Ken
1779640452
vÍnce
Pro
Sheet Author
Just a hunch, but I'm guessing that it's a case mismatch issue with the generated id.  Maybe try removing .toLowerCase I believe the VTT expects a mixed case id in the HTML to be a valid.  You can normalize within your sheetworker to help with testing/checks, but the actual row id that roll20 uses needs to be mixed.  At least that's my understanding.
Well, duh.  I'd swear I'd tried that, but I just tried again with a new sheet, and that does fix it. Thanks. And interesting. Maybe there's a checksum built into the id string.
1779641004
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
yep, while row ids will be lowercase when gotten via getSectionIDs, the initial creation needs to be fully cased.
Thanks for the confirmation.  I just took that change back to my full sheet, and it fixed my problem completely.