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

Adding Dynamic Buttons to Repeating Items

Can someone point me to documentation on how to add roll buttons with dynamic values? For example: <fieldset class="repeating_weapons"> <input type="text" name="attr_weapon_name"/> <span>Stone:</span> <input type="number" value="0" name="attr_weapon_enc"/> <span>Dmg:</span> <input class="shortText60" type="text" name="attr_weapon_dmg"/> <span>Attribute:</span> <select class="weapon_attr" name="attr_weapon_attr"> <option value="strength_mod">STR</option> <option value="dexterity_mod">DEX</option> </select> <span>Throw:</span> <span name="attr_weapon_throw"></span> <button type="roll" value="/roll {@attr_weapon_throw}" name="roll_weapon_throw"></button> </fieldset> This doesn't work. I assume, because it's in a repeating item, I need to do something more complex to get it to work.
1587785566
GiGs
Pro
Sheet Author
API Scripter
Its more likely because this is the wrong syntax <button type="roll" value="/roll {@attr_weapon_throw}" name="roll_weapon_throw"></button> This should be <button type="roll" value="/roll @{weapon_throw}" name="roll_weapon_throw"></button> There were two erros there: first the @ was inside the brackets not outside it, and second attr_ is not part of the attribute name. When you define an attribute like this: <span name="attr_weapon_throw"> it looks like the name is "attr_weapon_throw", but the "attr_"  is a special descriptor. It is not part of the name, it is a signal to the roll20 code to say "whjat follows is an attribute". This is because you can have names for attributes, roll buttons, and action buttons, and roll20 needs the name with the right prefix so it knows how to treat them. The prefix for each is attr_, roll_, and act_, and those prefixes are only used in the name= statement and are ignored afterwards. Thats why you can call a roll button named name="roll_weapon_throw" with %{weapon_throw} not %{roll_weapon_throw}. And that's why the actual attribute name for  <span name="attr_weapon_throw"> is @{weapon_throw}
I modified the HTML as suggested, but I still receive two error messages in the chat window when I click the button: No attribute was found for @{Ban Drel|weapon_throw} There was an error with your formula. Please try again. (Ban Drel is the Roll20-generated character name.) <div> <h3>Weapons</h3> <fieldset class="repeating_weapons"> <input type="text" name="attr_weapon_name"/> <span>Stone:</span> <input type="number" value="0" name="attr_weapon_enc"/> <span>Dmg:</span> <input class="shortText60" type="text" name="attr_weapon_dmg"/> <span>Attribute:</span> <select class="weapon_attr" name="attr_weapon_attr"> <option value="strength_mod">STR</option> <option value="dexterity_mod">DEX</option> </select> <span>Throw:</span> <span name="attr_weapon_throw"></span> <button type="roll" value="/roll @{weapon_throw}" name="roll_weapon_throw"></button> </fieldset> <input type="hidden" value="0" name="attr_small_weapon_count"/> <input type="hidden" value="0" name="attr_large_weapon_enc"/> </div> I thought it could caused by the attr_ and the roll_ having the same name, but changing the name of the roll_ to something unique still generates the same error.
1587823598
GiGs
Pro
Sheet Author
API Scripter
It might be because the attribute is defined only as a span. Try adding a hidden attribute with the same name just before it <input type="hidden" value="0" name="attr_weapon_throw"/> <span>Throw:</span> <span name="attr_weapon_throw"></span> I seem to remember seeing this with attribute-backed spans inside repeating sections before. If that's not the issue, I'll load it up in a custom sheet and see if I can figure it out.
1587823653

Edited 1587823718
Andreas J.
Forum Champion
Sheet Author
Translator
The "weapon_throw" doesn't seem to have a value. Do you have a sheetworker that gives it some value? Try add a value="0" to the weapon throw, or add: <input type="hidden" name="attr_weapon_throw" value="0"/> so the attribute at least has a starting value. the roll and attr having the same name shouldn't affect anything. Edit: jinxed by GiGs.
1587823959
GiGs
Pro
Sheet Author
API Scripter
Your suggestion is worth a try too Andreas. 
It was the <span> element. I changed it to <input type="number"/> and it works fine. Thank you! (I also added a default value to the field ;)
I just ran into the same problem, of a <span> element not working. I tried a bunch of things until I guessed right, and didn't find this thread until later (It is not easy to find by searching.) Since two people have encountered the same problem in a week, would it make sense to add it to the documentation somewhere? P.S. I ended up adding an <input type="hidden>, in addition to the span, because the span was easier to style. That also works. I also have two <fieldset> tags with the same data, and it turns out that each of them needs an <input> if they each have a button.