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

New Repeating Item Event Handler?

Looking through Roll20 sheet worker documentation and examples, I don't see a way to detect when a new item is added to a repeating section - when the "Add" button is clicked. Is there one? on(change) doesn't work in this instance. Instead, I have to wait until the contents of the repeating section are changed, which isn't what I want. For example, I have a limited list of armor types. When a new piece of armor is added to the character's "worn" list (a repeating section), I want to call a function that retrieves the armor option's armor class value and auto-display that in the "AC" <span> of the newly added item.
Assuming the armor's armor class value is in the repeating section, you can build a change event around that. on("repeating_armor:armor_value", function(){
First, I assume you meant to write the code snippet as an on( change :repeating_armor:armor_value") event... The on(change) event doesn't get fired when a new repeating item is added to a repeating item section. At least, not in my test function (it *does* work when I change the data in the newly added item, but that's not what I want to do.) If there's no event handler for when a new item is added to a repeating item section, why is that? And is there any other work-around besides forcing the end-user to make a change to the new item?
1587491093
GiGs
Pro
Sheet Author
API Scripter
omonubi said: First, I assume you meant to write the code snippet as an on( change :repeating_armor:armor_value") event... Did you mean to miss the opening quote before change there? The on(change) event doesn't get fired when a new repeating item is added to a repeating item section. At least, not in my test function (it *does* work when I change the data in the newly added item, but that's not what I want to do.) If there's no event handler for when a new item is added to a repeating item section, why is that? And is there any other work-around besides forcing the end-user to make a change to the new item? Can you show the code for the fieldset? If the field for the armour types is a select, give one of the options "selected" so it will be set when the fieldset row is created, triggering the change event.
Yes, there should be a "change" before that example. D'oh! You don't want to update the value when you add a repeating item anyway, as the data at that time is empty. You want the change to be when the value of the armor is updated, as the user fills it in after they have added it.