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 .
×
May your rolls be merry + bright! 🎄
Create a free account

Difficulty with Action Button inside repeating section

1671392333

Edited 1671393363
New to this stuff. I'm trying to implement a button to let me toggle editing on my repeating elements, but I seemingly can't even get the script to recognize that the button is clicked. Here is what I've got: <fieldset class="repeating_abilities"> <button type="action" name="act_abilityEdit">edit</button> </fieldset> <script type="text/worker"> on("clicked:repeating_abilities:abilityEdit", function() { console.log("hello"); }); </script> However, I'm getting no output to console, seems like my button either isn't recognizing that it is being clicked or the syntax for the javascript/event isn't correct -- I'm not sure where I'm going wrong here. Other buttons in the sheet are working just fine, as are on("change:repeating_abilities:attribute") functions. I can't figure out what I'm doing differenty from the example in the wiki here . Any help is appreciated! edit: <fieldset class="repeating_abilities"> <button type="action" name="act_edit">edit</button> </fieldset> <script type="text/worker"> on("clicked:repeating_abilities:edit", function() { console.log("hello"); }); </script> ^This works? Apparently it just doesn't like capital letters????
1671419995

Edited 1671420737
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
yes the listeners are lowercase only. This is one of several reasons why the best practice for attribute naming is snake_case or kebab-case and kebab-case for action button names. Other reasons include: The roll20 attribute/ability system is case insensitive so there is no difference between %{MYABILITY}, %{myability}, and %{MyAbIlIty}. Using a naming scheme that is all lower case prevents accidentally naming something the same. snake_case and kebab-case are much more human readable than camelCase, PascalCase, or nocase when in a large macro. This makes your development life easier, and will make the lives of your users easier when they go to make custom macros. Screenreaders have an easier time with snake_case and kebab-case than camel, Pascal, or nocase. This makes your sheet more accessible to a wider audience. However, do NOT  use snake_case for action buttons that are in repeating sections as the listener for these has a long standing bug where they will not be recognized if they have an underscore in their name. Because I like consistency, I just use kebab-case for all my action buttons. Edit: And, to put it on your radar, there is also a very bizarre (and long standing) bug that causes action buttons in repeating sections to not work if you change the CSS position property of the button or any ancestor element between it and the .repitem  div. Yes, this is bizarre. No I don't have an explanation for why css is affecting a javascript listener.
1671420235

Edited 1671420252
GiGs
Pro
Sheet Author
API Scripter
This doesn't surprise me, and was the first thing I was going to suggest trying :) There have been glitches with the names of action buttons specifically inside repeating sections. I cant remember noticing an issue with capital letters, but I always use lower case attribute names now so I wouldn't notice it.