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

Switching a simple dice roller button for an API button

November 19 (1 year ago)
Chris Jones
Pro
Sheet Author

I'm updating an older character sheet and porting a bunch of the stuff over into a newer format, and on my old sheet, when I ticked a box at the top of the sheet, it "switched" the visible button from the simple version of the dice roller to the API version. In moving things over, I appear to have broken something. and now I'm only seeing the simple dice roller button. While I could try and pick things apart to resolve it, I suspect there may be a cleaner way to do this beyond what was used before - but I haven't managed to find a good example of one. Does anyone have any tips, or some examples I can be pointed at?


Cheers

Chris

November 19 (1 year ago)

Edited November 20 (1 year ago)
vÍnce
Pro
Sheet Author

You can have two buttons (normal and api) then use css based on a checkbox to hide/show the appropriate button.
good example on the wiki;
https://wiki.roll20.net/CSS_Wizardry#Swap_Visible_Areas

example;

<div>
<span>Use API:</span>
<input type="checkbox" class="sheet-block-switch" name="attr_block_switch" value="1">
<button type="roll" name="roll_something" class="sheet-block-a" value="[[1d20 + @{selected|melee-mod}]]">Roll</button>
<button type="roll" name="roll_something_api" class="sheet-block-b" value="!script {{
--#title| Melee Attack
--=Roll|1d20 + @{selected|melee-mod}
--*GMLine|@{selected|token_name} rolled a [$Roll]}}">API
</button>
</div>
.charsheet .sheet-block-a,
.charsheet .sheet-block-switch:checked ~ .sheet-block-b {
display: block;
}

.charsheet .sheet-block-b,
.charsheet .sheet-block-switch:checked ~ .sheet-block-a {
display: none;
}





November 20 (1 year ago)
Chris Jones
Pro
Sheet Author

Thanks for that - appreciated. Unfortunately, I'm still seeing both buttons appear on my screen


<button class="sheet-block-b" title="Rolls Athletics" type='roll' name='roll_athleticsApi' value='!some text'></button>

<button class="sheet-block-a" type="roll" title="Non-API Athletics Roll" value="&{template:stuff} {{name=@{character_name}}} {{Rollname=Athletics}} {{NormalSuccesses=a bunch of text}}" name="roll_athleticsInlineDice"></button>


Everything else - the API toggle, the CSS, is identical to your post - what have I missed?



November 20 (1 year ago)

Edited November 20 (1 year ago)
vÍnce
Pro
Sheet Author
ou also have the hidden input, correct?

I was missing ".charsheet" in the first line of the css (I've updated the example), but that shouldn't have really caused an issue. You might post an example of your code, since the css might need to be adjusted depending on how your html written.


I added your two buttons as well and it works in my test;

.charsheet .sheet-block-a,
.charsheet .sheet-block-switch:checked ~ .sheet-block-b {
display: block;
}

.charsheet .sheet-block-b,
.charsheet .sheet-block-switch:checked ~ .sheet-block-a {
display: none;
}
<div>
<span>Use API:</span>
<input type="checkbox" class="sheet-block-switch" name="attr_block_switch" value="1">
<button type="roll" name="roll_something" class="sheet-block-a" value="[[1d20 + @{selected|melee-mod}]]">Roll</button>
<button type="roll" name="roll_something_api" class="sheet-block-b" value="!script {{
--#title| Melee Attack
--=Roll|1d20 + @{selected|melee-mod}
--*GMLine|@{selected|token_name} rolled a [$Roll]}}">API
</button>
<button class="sheet-block-b" title="Rolls Athletics" type='roll' name='roll_athleticsApi' value='!some text'>API</button>
<button class="sheet-block-a" type="roll" title="Non-API Athletics Roll" value="&{template:stuff} {{name=@{character_name}}} {{Rollname=Athletics}} {{NormalSuccesses=a bunch of text}}" name="roll_athleticsInlineDice">Roll</button>
</div>
November 20 (1 year ago)
Chris Jones
Pro
Sheet Author

Thanks for the reply


No, i don't have a Hidden input, and while I know what they are, I'm not sure where i'd put these in here (apologies - baby didn't sleep last night, so I didn't sleep last night). I've looked over my other sheets and tried some things, but that hasn't worked. What should this look like?


Cheers

Chris

November 20 (1 year ago)

Edited November 20 (1 year ago)
vÍnce
Pro
Sheet Author

Actually... I said hidden input, but it's really just the checkbox that is used for the toggle in the example.

 <input type="checkbox" class="sheet-block-switch" name="attr_block_switch" value="1">

Sometimes you have to use hidden inputs (it's just a copy of the checkbox toggle, but it is hidden from view ie display:none; ) Think, sheet "Settings" page. One area that controls the entire sheet... You can strategically place them in various parts of the sheet so that whatever you are trying to do on the sheet can happen in multiple sections.  It really just depends on the html hierarchy and your css rule to "touch" them.

The css portion of the example above assumes that your toggle checkbox is located as a sibling ie '~' of the buttons.  It sounds like you either need to move your toggle to be a sibling (same level as your buttons), adjust your css to drill down to the actual location of your buttons, and/or use a hidden copy of the toggle checkbox to be a sibling of your button.  Clear as mud? ;-)

November 21 (1 year ago)
Chris Jones
Pro
Sheet Author

Yeah, i had the checkbox input on my sheet.

I removed all my code and just worked with the snippet you provided, and as you said, that worked fine - but i've got all those elements present within my sheet, so i suppose it must boil down to your last point. I tried moving my checkbox to be part of the main character sheet div (as opposed to being at the tabs level), but i still don't see a change of behavior when i change the button. Regardless of where the checkbox is, i am only seeing the non API button displayed on the sheet, so it does at least appear to be hinding my API button, but it isn't revealing it on my change

November 22 (1 year ago)
vÍnce
Pro
Sheet Author

You might need to post your code(link...) in order to work out the css selectors correctly.  Feel free to DM if needed. Cheers