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

on("clicked:action_button" and repeating sections

March 24 (6 years ago)
vÍnce
Pro
Sheet Author

Can anyone confirm that action buttons that reside within a fieldset cannot be used as a sheetworker listener? 

I'm trying to use a Charmancer Action button: https://wiki.roll20.net/Charactermancer_Development_Documentation#clicked:.3Caction_button_name.3E within a repeating section to trigger some attribute changes.

example;

sheetworker's can detect on("clicked:action_button" but not on("clicked:repeating_foo:action_button"

If this is true, wouldn't it be worthwhile that on("clicked: behaved like the other listeners?

March 24 (6 years ago)
Kavini
Roll20 Production Team
Marketplace Creator
Sheet Author
Compendium Curator
I have managed to get this working by using on("clicked:repeating_foo") without identifying the action button in specific, this obviously limits you to one action button per repeating section entry.
March 24 (6 years ago)

Edited March 24 (6 years ago)
vÍnce
Pro
Sheet Author

Thanks Nic.  That might actually work for my particular use case. (of course after I just spent an hour working up a fake action button... lol)  Any chance we might get the on("clicked) listener to work "within" a repeating section? Thanks

March 24 (6 years ago)
Kavini
Roll20 Production Team
Marketplace Creator
Sheet Author
Compendium Curator

Unfortunately, this isn't at all my area, I'm just scrabbling around making character sheets as a hobbiest like everyone else here. That said, I will pass it on :)

March 24 (6 years ago)

Edited March 24 (6 years ago)
vÍnce
Pro
Sheet Author

Thanks Nic

Maybe the wiki should get a comment as well...  I'm happy to add something unless the page is only editable by roll20.

March 25 (6 years ago)

Edited March 25 (6 years ago)
Caden
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Greetings Vince,

Action buttons can be found in a repeating section like the example below. This issue in your example would be in using the extra underscore in ("clicked:repeating_foo:action_button"... in retrospect I do not know off the top of my head if an additional _ was the problem.


    on("clicked:repeating_quality:quality", (eventinfo) => {
const source = (eventinfo.sourceAttribute).slice(0, -8);
getAttrs([`${source}_flag_quality`], (v) => {
setAttrs({
[`${source}_flag_quality`]: (v[`${source}_flag_quality`] === "settings") ? "display" : "settings"
});
});
}); 

March 25 (6 years ago)
vÍnce
Pro
Sheet Author

Thanks Nic and Cassie.  I'll need to play around with it again.  Maybe later tonight. In the meantime, I ended up just making one of those input+span "mock" buttons and triggering off of that.  But the simplicity of the action button for such events is very nice.

March 26 (6 years ago)
Caden
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Greeting Vince,

I've been converting all my sheets. My Warhammer 40k Wrath & Glory sheet use them a LOT for the dice roller. I can provide more examples and try to help with further questions. They are sooooooo nice for getting rid of excess tedious code that the fake span buttons need. 

- Cassie

March 27 (6 years ago)

Edited March 27 (6 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Vince, I ran into this issue myself recently while working on the SF sheet. In the repeating section that you have your action button in, do you have a containing div that has a position property applied to it? Something like this (bolded):

HTML

<div class='buffs'>
    <!-- contains the buffs repeating section-->
    <fieldset class='repeating_section'>
        <div class='filter-container'>
            <button type='action' name='act_button'>Button</button>
        </div>
    </fieldset>
</div>

CSS

.repcontainer div{
    position:relative;
}

Javascript used to test

<script type='text/worker'>
    on('clicked:repeating_section:mod', (event)=>{console.log(`clicked:repeating_section:mod event: ${JSON.stringify(event)}`)});//This event will only be triggered if position:relative/absolute is NOT applied to the filter-container div.
    on('clicked:mod', (event)=>{console.log(`clicked:mod event: ${JSON.stringify(event)}`)});//This event will only be triggered if position is applied to the filter-container div. However it will not have repeating row info.
</script>

After eliminating code line by line until the events started firing correctly, I found that if you have a div with position:relative or absolute applied to it the event doesn't fire correctly. Position:static doesn't appear to cause the issue, but I have by no means tested all the possible position states. I also have no clue why a css position change would affect how a javascript event is passed since it certainly doesn't affect any other event generation in the sheetworker environment.

March 27 (6 years ago)

Edited March 27 (6 years ago)
vÍnce
Pro
Sheet Author

Who would have thought a child element's position would interfere with the js detection?  I'm still working on higher priority tasks ATM, but I will revisit this, since I'm primarily using action buttons on the sheet to add "presets" to a dice pool.  Thanks Scott

March 27 (6 years ago)
GiGs
Pro
Sheet Author
API Scripter

Have you raised that as a bug, Scott?

March 27 (6 years ago)
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator

Yes, I've brought it up.

March 27 (6 years ago)
GiGs
Pro
Sheet Author
API Scripter

Great. It is such a weird bug.

March 30 (6 years ago)

Edited July 21 (3 years ago)
vÍnce
Pro
Sheet Author

I finally got back around to this...


SOLVED:

Cassie's thought concerning the "_" within the button name was preventing the button from being properly detected by the sheet worker.


Button name's containing an underscore e.g "attack_roll"  inside a repeating section, ARE NOT DETECTED by the on("clicked: listener.

Once I changed the name to "attack-roll", suddenly the listener worked as expected.  It appears you can use an underscore in your button name outside of a repeating section, but not inside a repeating section.

Seems a little buggy to me.

Thanks for the help everyone.