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

Trying to hide buttons based on radio or checkbox

1546461039

Edited 1546465671
First of all... I've already gone through various posts here (and am using the CSS Wizardry suggestions to expand/collapse <div> sections in my custom sheet, but I can't for the life of me get the following problem licked... Objective:   In Traveller game, there's a thing called "Boon" and "Bane" rolls.  Essentially, a normal roll to succeed at something is 2d6;  a boon roll is 3d6kh2, and a bane is 3d6kl2.  I'm trying to create roll buttons that will detect the state of some sort of Boon/Bane/Normal selector and will make available a different set of buttons for each - with the appropriate {{roll = ...}} defined.  Building a row of each type of button was the easy part.  Getting only one set at a time to appear on the screen is a different problem. Here's a abbreviated form of the pertinent stuff I've got: In an area that forms a sort of header for the whole character sheet...     <div class="sheet-section sheet-bordered-section">         <input class="sheet-boon-bane-radio" type="radio" name="attr_boon-or-bane" value="0" checked>Normal</input>         <input class="sheet-boon-bane-radio" type="radio" name="attr_boon-or-bane" value="1">Boon</input>         <input class="sheet-boon-bane-radio" type="radio" name="attr_boon-or-bane" value="2">Bane</input>     </div> In the area where I'm trying to display the buttons... <div class="sheet-inner-body"> <table>     <div class="sheet-normal-rolls">          <input type="hidden" class="sheet-roll-state" name="attr_boon-or-bane"/> <!-- the same name as the three radio options -->             <tr align="center" class="sheet-normal-rolls">               <td><button>...stuff...</button></td> <!-- six buttons defined for "normal" rolls -->             </tr>     </div>         <div class="sheet-boon-rolls">             <input type="hidden" class="sheet-roll-state" name="attr_boon-or-bane"/>             <tr align="center" class="sheet-boon-rolls">               <td><button>...stuff...</button></td> <!-- six more buttons defined for "boon" rolls -->            </tr>         </div>         <div class="sheet-bane-rolls">             <input type="hidden" class="sheet-roll-state" name="attr_boon-or-bane"/>             <tr align="center" class="sheet-bane-rolls">               <td><button>...stuff...</button></td> <!-- six more buttons defined for "bane" rolls -->             </tr>         </div>         ... more table rows... </table> </div> Finally, the pertinent CSS: input.sheet-roll-state:not([value='0']) + .sheet-normal-rolls {     display: none; } input.sheet-roll-state:not([value='1']) + .sheet-boon-rolls {     display: none; } input.sheet-roll-state:not([value='2']) + .sheet-bane-rolls {     display: none; } NOTES: I have tried ~ instead of +         I have tried tr.sheet-normal-rolls... etc. My thinking was to use the <input type: hidden ... > tag to essentially reference the radio button value (by using the same attr_ name) - and then using CSS sibling relationship to 'connect' it to the <tr> sections that I want to have disappear. The end result of all this is as follows: The radio button set appears, I can select each of the three radio options. The attr_boon-bane-or-bane value is correctly updating (as seen on the Attributes & Abilities tab that Roll20 provides with a character sheet. .All 18 buttons appear.  (In other words, none of the three <tr> sections is getting the display : none; CSS setting. The only good news is that the buttons themselves work exactly as they're supposed to (so I've got that part right at least!) Any suggestions and help will be greatly appreciated.
1546465535

Edited 1546465574
GiGs
Pro
Sheet Author
API Scripter
Shouldn't the radio button be a select: <div class="sheet-section sheet-bordered-section">         <select class="sheet-boon-bane-radio" name="attr_boon-or-bane" > <option value="0" selected>Normal</option>          <option value="1">Boon</option>          <option value="2">Bane</option> </select> </div> The structure of your html and css strikes me as a bit weird. In this: <div class="sheet-normal-rolls">          <input type="hidden" class="sheet-roll-state" name="attr_boon-or-bane"/> <!-- the same name as the three radio options -->             <tr align="center" class="sheet-normal-rolls">               <td><button>...stuff...</button></td> <!-- six buttons defined for "normal" rolls -->             </tr>     </div> I'd move the input above the div, and use the div not the tr to determine visibility, like so:         <input type="hidden" class="sheet-roll-state" name="attr_boon-or-bane"/> <!-- the same name as the three radio options -->         <div class="sheet-normal-rolls">          <tr align="center" class="sheet-normal-rolls">               <td><button>...stuff...</button></td> <!-- six buttons defined for "normal" rolls -->             </tr>     </div> and then your css would be something like input.sheet-roll-state:not([value='0'])~div .sheet-normal-rolls {     display: none; } or  input.sheet-roll-state:not([value='0'])~div.sheet-normal-rolls {     display: none; } (css isnt my strong suit!)
I could try the option list vs radio button, but I'm not sure that's where the root problem is. (I already tried a series of checkboxes - and would have relied on worker scripts to make the checkboxes work like a radio - but even with independent checkboxes, I couldn't get selected sets of buttons to appear/disappear. I also already tried putting the <tr> in a <div> of its own (with the CSS then looking like you suggest)...  no difference in behavior.  I don't want to put the whole table into a <div> that would be sibling to the input because the rest of the table needs to stay visible regardless of what set of buttons appears above it. (I guess I could go with two tables, but then I have to make sure columns are aligned.)  But just to make sure I didn't change too much at once while I was trying different things, I'll put it back that way and see what happens.
As expected... no change if I promote the <input> and look for <div> siblings.  I'll give the <select> thing a try... can't hurt.
Got it!!! Apparently, it was my breaking up the table that was keeping things from working correctly. As soon as I split the table up into two parts, and was able to enclose the entire <table>...</table> structure within a <div>...</div>... the CSS works to show only the one <div> of buttons that agrees with the <input>. (I'm keeping the <select> version, too... I like the way it looks and I'll be able to do more formatting-wise with it. Thanks GiGs for letting me bounce this off you.  Sometimes you just need to 'talk out loud' with somebody listening!!!
Something you already know: everything has to happen inside of a div.  If you put the trigger inside its own div, it cannot affect what is outside said div.  Sheet workers can activate a hidden input, however. 
Yeah... my problem turned out to be that I started a table in an outer div, then tried to manipulate one row of it in a lower one.  I *think* what happened was I got "order-of-precedence"-ed, with the CSS taking second-chair to the table itself.  Reworked the html... a bit more duplication than I would have wanted, but it's working beautifully now.