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

[Sheet Worker] Can you use "on clicked:" for a button in a repeating area?

And if so, how?  This doesn't work: <fieldset class="repeater">     ...     <input type=button name=act_my-button>     ... </fieldset> on ("clicked:repeater:my-button", function(eventInfo) {     ... }) The event handler never gets triggered.  If it matters, the button is also triggering a rolltemplate.- and that works. What I need to do is change some attributes (all within the context of the single repeating row) as a consequence of the button being hit.  Specifically, the button generates a ranged weapon attack roll, and I'm trying to decrease the loaded ammunition in the weapon when it is fired. All suggestions welcome!
1547241191

Edited 1547241248
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
In a specific situation, it is possible to use the on:clicked  event listener. First though, there's a misconception in your code above. Buttons are not input elements, they are their own html element: <input type=button name=act_my-button> should be <button type='action' name='act_my-button'>Button Text</button> or <button type='roll' name='roll_my-button' value='what you want sent to chat'>Button Text</button> Both of these buttons are valid on character sheets, but have different effects. The action button can be clicked for an effect to take place (and you would use on:clicked  to listen for that click). The roll button sends a macro to chat and clicking it does not create an event for on:clicked  to listen for. So, if you're using an action button, then yes you can listen for the click. Additionally, I might recommend some changes to your proto sheetworker: on ("clicked:repeater:my-button", function(eventInfo) {     ... }) This is technically correct, but unless you are planning on having buttons with the same name in multiple repeating sections, you could simply change this to: on ("clicked:my-button", function(eventInfo) {     ... }) Hope that all helps, Scott
The <input type="button"> vs <button...> was just carelessness.  (I was stripping down my code to siimplify the example and got a bit carried away.) So, the short answer is... I can have a button that EITHER triggers a sheet worker OR triggers a roll template.   I sorta expected that.  So the next question becomes... can I have the sheetworker trigger the roll? (Oh, and thx for the simplifer on the "clicked:"  Does that apply to on("changed:repeating-attrib... as well?)
1547251513

Edited 1547251659
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Bob O. said: So, the short answer is... I can have a button that EITHER triggers a sheet worker OR triggers a roll template.&nbsp;&nbsp; I sorta expected that.&nbsp; So the next question becomes... can I have the sheetworker trigger the roll? Short answer is no. The slightly longer answer is that you might be able to accomplish this whenever charactermancer functions go live for the community sheet authors&nbsp; Edit:as for the change event,see the wiki for full details:&nbsp;<a href="https://wiki.roll20.net/Sheet_Worker_Scripts#change:.3Cattribute_name.3E" rel="nofollow">https://wiki.roll20.net/Sheet_Worker_Scripts#change:.3Cattribute_name.3E</a>
Scott C. said: ... Additionally, I might recommend some changes to your proto sheetworker: on ("clicked:repeater:my-button", function(eventInfo) { &nbsp;&nbsp;&nbsp; ... }) This is technically correct, but unless you are planning on having buttons with the same name in multiple repeating sections, you could simply change this to: on ("clicked:my-button", function(eventInfo) { &nbsp;&nbsp;&nbsp; ... }) Hope that all helps, Scott FYI... using the "clicked:repeater:my-button" didn't seem to work at all, but clicked:my-button does! So... I can create an "action" button in my repeating area... and I can get into an event listener when it gets clicked. But... The sheet worker doesn't seem to know what row it was called from... attempts to use the&nbsp; "repeater_attribute-name" syntax that works for on:change events that are limited to attributes within the row doesn't work (I get an error indicating that there's no current row id).&nbsp;&nbsp; And since the "clicked" event doesn't pass an eventInfo object, I use the can't use the "pluck the row ID out of eventInfo.sourceAttribute". So... any ideas on how I can tell the script what row I'm working on?
1547761844

Edited 1547762556
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hmm, that's interesting. There's no event info at all? Hmm. I'd say it's a bug/not fully implemented feature. I'll have to dig in and do some testing myself. EDIT: Hmm, interesting, so there is an event created, and it does have the expected keys, but all of them except for triggerName are undefined.
I used the "fake button made from transparent checkbox over a span that looks like a button" approach to get around this for now, but maybe someday they'll provide a proper way to do this.