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

Can't add more than 1 item to repeating section.

I have a character sheet I've been gradually working on as I play Fellowship with my friends, but I've run into a strange issue. There are two nearly-identical repeating sections, one for "Gear" and one for "Other Items" (the difference is important to the game, as Gear can be refreshed). Gear works fine, but when more than one item is added to the Other Items section, it disappears when a value is set. Once I enter a value for "Gear Name" in the above screenshot, when I click away anywhere else the second item section vanishes. This has happened on all character sheets in the game, and only on the second item in "Other Items". I only have a custom script running and I disabled that to test, but it didn't have any effect. I also have some sheet worker scripts, but they either monitor other stats or trigger on sheet open, so they wouldn't activate when I set this value (they also don't delete any repeating section rows). This is the code for the two repeating sections, one of which works and the other doesn't:                 <label class="sheet-gear"><span data-i18n="gear">Gear</span>:</label>                 <fieldset class="repeating_gear">                     <label class="sheet-gear-name"><input type="text" name="attr_gearname" data-i18n-placeholder="gear-name" placeholder="Gear Name"/><span class="sheet-gear-uses"><input type="number" name="attr_gearuses" />/<input type="number" name="attr_gearuses_max" /></span></label>                     <textarea rows="2" cols="50" name="attr_geardesc" data-i18n-placeholder="gear-tags-desc" placeholder="Gear Tags & Description"></textarea>                 </fieldset>                                  <label class="sheet-other-items"><span data-i18n="other-items">Other Items</span>:</label>                 <fieldset class="repeating_other_gear">                     <label class="sheet-gear-name"><input type="text" name="attr_gearname" data-i18n-placeholder="gear-name" placeholder="Gear Name"/><span class="sheet-gear-uses"><input type="number" name="attr_gearuses" />/<input type="number" name="attr_gearuses_max" /></span></label>                     <textarea rows="2" cols="50" name="attr_geardesc" data-i18n-placeholder="gear-tags-desc" placeholder="Gear Tags & Description"></textarea>                 </fieldset> Has anyone seen this kind of behavior before and know what's causing it? Should I not be using the same attribute names for a second repeating section, even though they'll have different row IDs and a different section name?
I have seen a similar situation happen in the 5e OGL character sheet, specifically with the resources. As far as I can tell, the problem happens because you are attempting to create an attribute with a current value and a max value, but aren't setting either value. The fix for the OGL sheet is to set the resource values first before setting the resource name. Maybe this approach is also necessary for your sections.
Thanks for the suggestion. Unfortunately, when I try setting the gearuses_max value first, the item disappears when I unfocus that box, just like the other values.
1523380866

Edited 1523381108
Dana Lexa
Sheet Author
Another odd behavior I've just noticed is that I can't delete the first item after I've created it, either. I can in the first, working Gear section though. In the javascript log, the first DELETE REPEATING ROW is from "Gear", the second is from "Other Items": I don't see anything interesting in the log when I try to create a new row (just a list of "Triggering for change:..." messages, no error)
1523381207

Edited 1523381228
Jakob
Sheet Author
API Scripter
That's your culprit <fieldset class="repeating_other_gear"> the repeating section name may not contain an underscore.
Alright, I solved my own issue based on that log. The problem was I had a name with an underscore for the second repeating section. When I changed "repeating_other_gear" to "repeating_othergear", the section behaved normally. I guess the extra underscore was throwing off the repeating sections code.
Jakob said: That's your culprit <fieldset class="repeating_other_gear"> the repeating section name may not contain an underscore. I figured it out on my own, but thank you for providing the answer!
Amusing epilogue: I wrote a quick API script to find and rename all attributes including "repeating_other_gear" to "repeating_othergear" and it not only transferred the visible items, but all the previous attempts that had disappeared:
1523384768
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Kyle G. said: I have seen a similar situation happen in the 5e OGL character sheet, specifically with the resources. As far as I can tell, the problem happens because you are attempting to create an attribute with a current value and a max value, but aren't setting either value. The fix for the OGL sheet is to set the resource values first before setting the resource name. Maybe this approach is also necessary for your sections. I've had this problem on the Shaped Sheet. If you set a value in a repeating section, you have to set the name first, or it disappears when you exit the field.
1523414688
vÍnce
Pro
Sheet Author
I might be wrong, but I believe you should make sure all of your attribute names are unique even if they reside within a uniquely named repeating fieldset.
1523415170
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
I don't think this is true. I have had characters with multiple instances of a feat, for instance. Repeating fields are called in macros by a number corresponding to their order. $1, $2, and so forth.
1523417478
vÍnce
Pro
Sheet Author
keithcurtis said: I don't think this is true. I have had characters with multiple instances of a feat, for instance. Repeating fields are called in macros by a number corresponding to their order. $1, $2, and so forth. I think you're right Keith.  Seems we had issues with repeating attribute names on the PF sheet...  It may have been an issue of using the same attribute name inside as well as outside of a repeating section.  Logically it doesn't seem there would be a problem since the repeating class name "should" make the attribute name within unique, as you pointed out.  I can't recall the exact problem we had... ;-(
1523422716

Edited 1523423365
The wiki recommends making sure that attribute names within repeating sections are globally unique (see the Note at the end of this section: <a href="https://wiki.roll20.net/Building_Character_Sheets#Repeating_Sections" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets#Repeating_Sections</a>) Though when I have done this by accident on my custom sheet, I did not see any problems. Still, just in case, I went back through and corrected my attribute names.
1523425680
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Rabulias said: The wiki recommends making sure that attribute names within repeating sections are globally unique (see the Note at the end of this section: <a href="https://wiki.roll20.net/Building_Character_Sheets#Repeating_Sections" rel="nofollow">https://wiki.roll20.net/Building_Character_Sheets#Repeating_Sections</a> ) Though when I have done this by accident on my custom sheet, I did not see any problems. Still, just in case, I went back through and corrected my attribute names. I believe that is referring to the names of the attribute fields , not the text values that are put into those fields by the user. I was talking about the values. I.e. if I had a Class Feature of "Rage" in a repeating attribute, nothing would be broken by having another feature in that repeating attribute called "Rage". The specific behavior I was referring to is apparently one of timing. The name field has to be filled in first.&nbsp; If I start to input the Description before I put in the name, the sheet panics and drops that specific repeated attribute before I can put in the name.
Yes, I was referring to attribute names as attribute field names. I have never had a problem with the same name value in a repeating field, though I can only recall one time that I did that... I also never had a problem filling out other fields before the name field. There is nothing special about a name field; to a repeating section, all fields look about the same, I would guess. It's possible that a sheetworker and/or API script working some behind-the-scenes magic would wig out if the name field does not exist when other data is populated, but I don't think there would be any errors from Roll20 itself.
As far as I can tell from my issue, the timing is this: 1. The sheet checks for all attributes that start with the repeating section name, and builds a list of rows based on the row IDs of those attributes 2. The sheet creates an HTML section for each row ID in the list and populates them with the matching attribute values 3. When the add button is clicked, a temporary HTML section with a new row ID is created 4. As soon as one of the attributes in that HTML section changes, it is saved and steps 1 and 2 run again to update the list and HTML sections So, when I created a new row with an invalid name (extra underscore), the first attribute I changed was saved but then it couldn't be found by whatever function checks for attributes in step 2, and the HTML for that row ID wasn't added when the HTML was updated based on the list of rows IDs. Based on that observation, maybe the attribute name for the "name" field is valid for a repeating section but the other attribute names aren't (they have extra underscores or some other confusing character). So setting a name creates an attribute with a valid row ID that will generate HTML. The rest won't be found by the HTML-generating function, but if there's a name and the HTML section is already generated, those attributes will read and write properly. Without a name, as soon as one is changed, the list updates and that row ID can't be found so it vanishes. At least, that's my speculation, without actually looking at the shaped sheet or any of its repeating sections.