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

Sheetworkers: toggle checkbox on then off using action button

1572766019

Edited 1572767416
vÍnce
Pro
Sheet Author
I would like to toggle a checkbox on then off after a single click of an action button.  Is this possible?  I want to momentarily style an html element when an action button is pressed.   example html <button type="action" name="act_dice_pool_clear" class="dice-footer-clear">Clear Pool</button> <input class="hidden roll-indicator" type="checkbox" name="attr_roll_the_dice_flag" value="1" readonly/> <button class="dice-pool" type="roll" name="roll_the_dice" value="1d20">Roll</button> example sheetworker (I realize this just toggles the state of the checkbox, but I would like to set it to "1", trigger my css, then reset to "0")         on("clicked:act_dice_pool_clear", function () {             console.log(">>>> Change Detected: Clear Dice Pool <<<<");             getAttrs(["roll_the_dice_flag"], function (values) {                 const roll_the_dice_flag = parseInt(values.roll_the_dice_flag, 10) || 0;                 var buttonState = roll_the_dice_flag                              if (roll_the_dice_flag===0) {                     buttonState=1                 }                 else {                     buttonState=0                 }                 setAttrs({                     roll_the_dice_flag: buttonState                 });             });         }); TIA.
1572767049

Edited 1572767076
GiGs
Pro
Sheet Author
API Scripter
Vince, your posts are lately havijg format that makes them hard to read. If you look up at the formatting bar, after B I U S, theres an erase button. If you select a section of a post and click that, it will reset the formatting for the appropriate section. Code formatting will be reset to basic code, text formatting to basic text, etc.  On to your question: One way would be to have a sheet worker on the checkbox, that resets it to zero. On('change:roll_the_dice_flag', function(event) { const flag = parseInt(event.newValue) || 0; // you dont need to include the ,10      if (flag === 1) setAttrs({ roll_the_dice_flag: 0},  {silent:true} ); }
1572767664

Edited 1572768030
vÍnce
Pro
Sheet Author
GiGs said: Vince, your posts are lately havijg format that makes them hard to read. If you look up at the formatting bar, after B I U S, theres an erase button. If you select a section of a post and click that, it will reset the formatting for the appropriate section. Code formatting will be reset to basic code, text formatting to basic text, etc.  On to your question: One way would be to have a sheet worker on the checkbox, that resets it to zero. On('change:roll_the_dice_flag', function(event) { const flag = parseInt(event.newValue) || 0; // you dont need to include the ,10      if (flag === 1) setAttrs({roll_the_dice_flag: 0}, {silent:true}); } Thanks GiGs.  Not sure why my formatting is screwy, although I do copy paste from outside of roll20.  I didn't realize the cool little eraser worked as such.  I tried it on my post above.  Look any better? I tried something similar with the roll_the_dice_flag but I must have had something messed up.   I'll give this a spin.  Thank you. Edit/Update:  it works!
1572768489
GiGs
Pro
Sheet Author
API Scripter
Great! And yes, that's cleaned up your post perfectly.