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

Custom checkbox that hides a div

1595375796

Edited 1595375822
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I have been fudging with this for a few days. I cannot figure out what I am doing wrong. I need to hide the Weapon Notes. <div class="toggle-container"> <input type="hidden" class="toggle" name="attr_show_flag" value="1" /> <button type="action" name="act_show" class="toggle"> <span style="font-family:'Pictos'" class="checked">{</span> <span style="font-family:'Pictos'" class="notchecked">}</span> </button> </div> <div class="weapondate">Weapon Data Goes Here</div> <!-- Hide this div when not checked --> <div class="weaponnotes">Weapon Notes Go Here</div> <script type="text/worker"> // Register the click handler to all specified buttons. const toggleList = ["show"]; toggleList.forEach(function(button) { on(`clicked:${button}`, function() { const flag = `${button}_flag`; // Check the current value of the hidden flag. getAttrs([flag], function(v) { // Update the value of the hidden flag to "1" for checked or "0" for unchecked. setAttrs({ [flag]: v[flag] !== "1" ? "1" : "0" }); }); }); }); </script> /* Configure the button styling. This example makes it look like a checkbox. */ button.sheet-toggle { padding: 0; cursor: pointer; width: 16px; height: 16px; text-shadow: 0 0 10px #FF6B48, 2px 2px 2px rgba(255,107,72,0); color: #FC1212; border: 2px ridge #77787b; background-color: black; box-shadow: inset 2px 1px 2px rgba(255, 255, 255, 0.075); font-family: "Pictos" font-size: 18px; } /* Hide the "checked" section of the toggle if the attribute value is not "1". */ input.sheet-toggle:not([value="1"]) ~ button.sheet-toggle > span.sheet-checked { display: none; } input.sheet-toggle:not([value="0"]) ~ button.sheet-toggle > span.sheet-notchecked { display: none; } input.sheet-toggle:not(:checked) ~ div.sheet-weaponnotes { display: none; } .sheet-toggle-container { float:left; } .sheet-weapondata { float:left; }
1595377521
Andreas J.
Forum Champion
Sheet Author
Translator
I see you based this on the CSS Wizardry example, did you make the example work before you created your version of it? Maybe the other example just little below it would work better for what you want: <a href="https://wiki.roll20.net/CSS#Alternative_Checkboxes" rel="nofollow">https://wiki.roll20.net/CSS#Alternative_Checkboxes</a>
1595378803
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
That still does not solve the hiding of the div problem I am having. &lt;input type="hidden" class="direction" name="attr_direction" value="down" /&gt; &lt;button type="action" name="act_direction_toggle" class="direction"&gt; &lt;span style="font-family:'Pictos'" class="down"&gt;{&lt;/span&gt; &lt;span style="font-family:'Pictos'" class="right"&gt;}&lt;/span&gt; &lt;/button&gt; &lt;div class="weapondate"&gt;Weapon Data Goes Here&lt;/div&gt; &lt;!-- Hide this div when not checked --&gt; &lt;div class="weaponnotes"&gt;Weapon Notes Go Here&lt;/div&gt; &lt;script type="text/worker"&gt; on("clicked:direction_toggle", function() { // Check the current value of the hidden attribute. getAttrs(["direction"], function(v) { // Toggle the hidden attribute value between "down" and "right" setAttrs({ "direction": v["direction"] !== "down" ? "down" : "right" }); }); }); &lt;/script&gt; /* Clear default button styling */ button.sheet-direction { padding: 0; cursor: pointer; width: 16px; height: 16px; text-shadow: 0 0 10px #FF6B48, 2px 2px 2px rgba(255,107,72,0); color: #FC1212; border: 2px ridge #77787b; background-color: black; box-shadow: inset 2px 1px 2px rgba(255, 255, 255, 0.075); font-size: 18px; } /* Hide the section(s) that do not match the attribute value */ input.sheet-direction:not([value="down"]) + button.sheet-direction &gt; span.sheet-down { display: none; } input.sheet-direction:not([value="right"]) + button.sheet-direction &gt; span.sheet-right { display: none; } input.sheet-direction:not([value="down"]) + button.sheet-direction &gt; div.sheet-weaponnotes { display: none; }
1595384194
Finderski
Pro
Sheet Author
Compendium Curator
Try adding this: .sheet-direction[value="down"] ~ .sheet-weaponnotes { display: none; } The problem I see is you're using + instead of ~. The + means the input needs to be right next to the element you want to impact. The ~ just means it needs to be on the same level.
1595425137

Edited 1595425226
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Finderski said: Try adding this: .sheet-direction[value="down"] ~ .sheet-weaponnotes { display: none; } The problem I see is you're using + instead of ~. The + means the input needs to be right next to the element you want to impact. The ~ just means it needs to be on the same level. I changed the css and still no effect on the div.sheet-weaponnotes. The switch is switching as designed however it is the weaponnotes that I wish to hide/show when it is clicked. /* Clear default button styling */ button.sheet-direction { padding: 0; cursor: pointer; width: 16px; height: 16px; text-shadow: 0 0 10px #FF6B48, 2px 2px 2px rgba(255,107,72,0); color: #FC1212; border: 2px ridge #77787b; background-color: black; box-shadow: inset 2px 1px 2px rgba(255, 255, 255, 0.075); font-size: 18px; } /* Hide the section(s) that do not match the attribute value */ input.sheet-direction:not([value="down"]) ~ button.sheet-direction &gt; span.sheet-down { display: none; } input.sheet-direction:not([value="up"]) ~ button.sheet-direction &gt; span.sheet-up { display: none; } input.sheet-direction:not([value="up"]) ~ button.sheet-direction &gt; div.sheet-weaponnotes { display: none; }
1595427868
Finderski
Pro
Sheet Author
Compendium Curator
This works for me... HTML: &lt;input type="hidden" class="sheet-direction" name="attr_direction" value="down" /&gt; &lt;button type="action" name="act_direction_toggle" class="direction"&gt; &lt;span style="font-family:'Pictos'" class="down"&gt;{&lt;/span&gt; &lt;span style="font-family:'Pictos'" class="right"&gt;}&lt;/span&gt; &lt;/button&gt; &lt;div class="weapondate"&gt;Weapon Data Goes Here&lt;/div&gt; &lt;!-- Hide this div when not checked --&gt; &lt;div class="sheet-weaponnotes"&gt;Weapon Notes Go Here&lt;/div&gt; &lt;script type="text/worker"&gt; on("clicked:direction_toggle", function() { // Check the current value of the hidden attribute. getAttrs(["direction"], function(v) { // Toggle the hidden attribute value between "down" and "right" setAttrs({ "direction": v["direction"] !== "down" ? "down" : "right" }); }); }); &lt;/script&gt; CSS /* Clear default button styling */ button.sheet-direction { padding: 0; cursor: pointer; width: 16px; height: 16px; text-shadow: 0 0 10px #FF6B48, 2px 2px 2px rgba(255,107,72,0); color: #FC1212; border: 2px ridge #77787b; background-color: black; box-shadow: inset 2px 1px 2px rgba(255, 255, 255, 0.075); font-size: 18px; } /* Hide the section(s) that do not match the attribute value */ input.sheet-direction:not([value="down"]) ~ button.sheet-direction &gt; span.sheet-down { display: none; } input.sheet-direction:not([value="up"]) ~ button.sheet-direction &gt; span.sheet-up { display: none; } .sheet-direction[value="down"] ~ .sheet-weaponnotes { display: none; }
1595428527
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Thank you so much Sir! I have been pounding my head against this for a few days now.
1595429594
Finderski
Pro
Sheet Author
Compendium Curator
Happy to help. :)
1596383856

Edited 1596383968
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I moved the hide button into the main sheet and broke it. I cannot figure out how to fix it. &lt;div class="cbt"&gt; &lt;div class="combat"&gt; &lt;div class="weaponheader"&gt; &lt;div class="col0"&gt;Weapon&lt;/div&gt; &lt;div class="col1"&gt;Skill&lt;/div&gt; &lt;div class="col2"&gt;AP&lt;/div&gt; &lt;div class="col5"&gt;/&lt;/div&gt; &lt;div class="col2"&gt;BD&lt;/div&gt; &lt;div class="col3"&gt;Range&lt;/div&gt; &lt;div class="col4"&gt;Ammo&lt;/div&gt; &lt;/div&gt; &lt;fieldset class="repeating_weapons"&gt; &lt;div class="weaponrow"&gt; &lt;input type="hidden" class="hide" name="attr_hide" value="down" /&gt; &lt;button type="action" name="act_hide_toggle" class="hide"&gt; &lt;span style="font-family:'Pictos'" class="right"&gt;]&lt;/span&gt; &lt;span style="font-family:'Pictos'" class="down"&gt;}&lt;/span&gt; &lt;/button&gt; &lt;div class="rollcol"&gt;&lt;button type=roll class="btech" name="attr_atkroll" value="[[2d6+?{Modifier|0}]]"&gt;&lt;/button&gt;&lt;/div&gt; &lt;div class="col0"&gt;&lt;input type="text" name="attr_skilllname" placeholder="Skill Name"/&gt;&lt;/div&gt; &lt;div class="col1"&gt;&lt;input type="text" name="attr_skilllvl" value="0"/&gt;&lt;/div&gt; &lt;div class="col2"&gt;&lt;input type="text" name="attr_ap" value="0"/&gt;&lt;/div&gt; &lt;div class="col5"&gt;/&lt;/div&gt; &lt;div class="col2"&gt;&lt;input type="text" name="attr_bd" value="0"/&gt;&lt;/div&gt; &lt;div class="col3a"&gt;&lt;input type="text" name="attr_short-range" value="0"/&gt;&lt;/div&gt; &lt;div class="col3"&gt;&lt;input type="text" name="attr_medium-range" value="0"/&gt;&lt;/div&gt; &lt;div class="col3"&gt;&lt;input type="text" name="attr_long-range" value="0"/&gt;&lt;/div&gt; &lt;div class="col3"&gt;&lt;input type="text" name="attr_extreme-range" value="0"/&gt;&lt;/div&gt; &lt;div class="col4"&gt;&lt;input type="text" name="attr_ammo" value="0"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="weaponnotes"&gt; &lt;div class="col0"&gt;Notes&lt;/div&gt; &lt;div class="col1"&gt;&lt;input type="text" name="attr_notes"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/div&gt; &lt;/div&gt; &lt;script type="text/worker"&gt; on("clicked:hide_toggle", function() { // Check the current value of the hidden attribute. getAttrs(["hide"], function(v) { // Toggle the hidden attribute value between "down" and "right" setAttrs({ "hide": v["hide"] !== "down" ? "down" : "right" }); }); }); &lt;/script&gt; /* Hide/Show Button */ button.sheet-hide { padding: 0; cursor: pointer; width: 16px; height: 16px; text-shadow: 0 0 10px #FF6B48, 2px 2px 2px rgba(255,107,72,0); color: #FC1212; border: 2px ridge #77787b; background-color: black; box-shadow: inset 2px 1px 2px rgba(255, 255, 255, 0.075); font-size: 16px; float: left; } /* Hide the section(s) that do not match the attribute value */ input.sheet-hide:not([value="right"]) ~ button.sheet-hide &gt; span.sheet-right { display: none; } input.sheet-hide:not([value="down"]) ~ button.sheet-hide &gt; span.sheet-down { display: none; } .sheet-hide[value="right"] ~ .sheet-cbt .sheet-combat .sheet-weaponnotes { display: none; }
1596401823
Andreas J.
Forum Champion
Sheet Author
Translator
The sheetworker stopped working when you put the stuff inside a repeating section, as the full name of the stat changes. So you need to take into account the change in your sheetworker for making it work again. And no, I'm not great at (repeating section + sheetworker) combo so don't know exactly what need to be changed, but I'm pretty sure that is the problem here.
1596402150
GiGs
Pro
Sheet Author
API Scripter
Good call, Andreas. The sheet worker needs to include the name of the repeating section, so this should work if thats the only issue here: on("clicked:repeating_weapons:hide_toggle", function() { // Check the current value of the hidden attribute. getAttrs(["repeating_weapons_hide"], function(v) { // Toggle the hidden attribute value between "down" and "right" setAttrs({ repeating_weapons_hide: v["repeating_weapons_hide"] !== "down" ? "down" : "right" }); }); });
1596422566
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I hope so....I'l let you know
1596462514
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
That doesn't seem to work The hidden input is not being triggered.
1596463551
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
So this change now triggers the hidden input. however the div is not hide/showing on("clicked:repeating_weapons:hidetoggle", function() { // Check the current value of the hidden attribute. getAttrs(["repeating_weapons_hide"], function(v) { // Toggle the hidden attribute value between "down" and "right" setAttrs({ "repeating_weapons_hide": v["repeating_weapons_hide"] !== "down" ? "down" : "right" }); }); });
1596465228
Kraynic
Pro
Sheet Author
What happens if you move the hidden input to the last line of your weaponrow div.&nbsp; Or maybe between the weaponrow and weaponnotes divs.&nbsp; For some reason, I was thinking it had to be right before the div you wanted to hide/reveal.
1596466707
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Strangely that breaks the action button and doesn't activate the css.
1596467340
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
Here are links to the gist. <a href="https://gist.github.com/ssveter1/ed98eae7f5f476b42c63ca2980456516" rel="nofollow">https://gist.github.com/ssveter1/ed98eae7f5f476b42c63ca2980456516</a> <a href="https://gist.github.com/ssveter1/7b3bff2ea8e13bbbabda5d9f07689d29" rel="nofollow">https://gist.github.com/ssveter1/7b3bff2ea8e13bbbabda5d9f07689d29</a>
1596468134
GiGs
Pro
Sheet Author
API Scripter
The code you originally posted here:&nbsp; <a href="https://app.roll20.net/forum/permalink/9028871/" rel="nofollow">https://app.roll20.net/forum/permalink/9028871/</a> uses an act_hide_toggle button I posted a sheet worker for that button, you said it didnt work, then posted that it did work with this line:&nbsp; on("clicked:repeating_weapons:hidetoggle", function() { That shouldnt work. But now I see you've changed the code in the sheet, so the code doesnt match the code you posted above. You've changed it since asking for help and didnt say so. Who knows what other changes have been made? It's hard to help you if you keep changing the code without stating so. I dont have much time to help at the moment, so I'll leave this one for other people.&nbsp;
1596468567
Kraynic
Pro
Sheet Author
The only other thing I can think of is moving your weaponnotes div inside the weaponrow div.&nbsp; From one of my sheets: &lt;fieldset class="repeating_meleeattacks"&gt; &lt;div class='mattack-grid-container' &gt; &lt;input class='mattack-label parchment' type="text" value="" title='Weapon name that will display in template header' name="attr_weapon_attack" placeholder="Weapon Name" /&gt; &lt;button class='meleedice' type='roll' title='Strike (Attack) Roll with Damage' name='roll_meleeattack' value="@{whispertoggle}&amp;{template:custom} {{color=blue}} {{title=**@{nametoggle}**}} {{subtitle=attacks with @{weapon_attack}}} {{Attack= [[d20cs&gt;@{critical}+@{weapon_strike}[strike]+@{strike}[HtH]+@{pp_bonus}[PP]+@{mtemp_strike}[temp]]]}} {{Damage= [[@{weapon_damage}+@{damage}[HtH]+@{ps_bonus}[PS]+@{mtemp_damage}[temp]]]}} {{desc=@{mattack_reference}}}"&gt;Strike&lt;/button&gt; &lt;button class='meleedice' type='roll' title='Parry Roll' name='roll_meleeparry' value="@{whispertoggle}&amp;{template:custom} {{color=grey}} {{title=**@{nametoggle}**}} {{subtitle=parries with @{weapon_attack}}} {{Parry= [[d20+@{weapon_parry}[parry]+@{parry}[HtH]+@{pp_bonus}[PP]+@{mtemp_parry}[temp]]]}}"&gt;Parry&lt;/button&gt; &lt;button class='meleedice' type='roll' title='Damage Roll' name='roll_meleedamage' value="@{whispertoggle}&amp;{template:custom} {{color=red}} {{title=**@{nametoggle}**}} {{subtitle=lashes out}} {{@{nametoggle}'s @{weapon_attack} deals= [[@{weapon_damage}+@{damage}[HtH]+@{ps_bonus}[PS]+@{mtemp_damage}[temp]]]}} {{desc=@{mattack_reference}}}"&gt;Damage&lt;/button&gt; &lt;input class='damage-dice parchment' type="text" title='Damage Dice Calculation other than HtH and PS' value="" name="attr_weapon_damage" placeholder="xdy+z" /&gt; &lt;input type='checkbox' title='Show Bonus and Notes Fields' name='attr_toggle_mbonus' value="1"&gt; &lt;input class='mbonus-toggle' type='hidden' name='attr_toggle_mbonus'&gt; &lt;div class='mbonus-hide'&gt; &lt;div class='mbonus-container'&gt; &lt;h5&gt;Strike Bonus&lt;/h5&gt; &lt;h5&gt;Parry Bonus&lt;/h5&gt; &lt;h5&gt;Notes&lt;/h5&gt; &lt;input class='mattack-bonus parchment' type="text" title='Strike Bonuses other than HtH or PP' value="0" name="attr_weapon_strike" /&gt; &lt;input class='mattack-bonus parchment' type="text" title='Parry Bonuses other than HtH or PP' value="0" name="attr_weapon_parry" /&gt; &lt;textarea class='mattack-notes parchment' type="text" title='Special Note About This Attack' value="" name="attr_mattack_reference" &gt;&lt;/textarea&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/fieldset&gt; div.sheet-mbonus-hide { display: none; } input.sheet-mbonus-toggle[value='1']~div.sheet-mbonus-hide { display: block; } I'm just using a checkbox on mine, so no script.&nbsp; But you will notice the hidden attribute is on the same "layer" of html, and right before the div that will be hidden/revealed.&nbsp; I looked at the css wizardry page and building a character sheet wiki page and couldn't find a reference to where that hidden input needs to be.&nbsp; I'm relatively certain that it has to be on the same "layer" of html that the div you want to hide is on, so (if that is right) it can't work from inside a preceding div as you have it set up.&nbsp;
1596471701
SᵃᵛᵃǤᵉ
Sheet Author
API Scripter
I am thinking about going back to old school way. I just like the cool buttons I made.
1596472124
Kraynic
Pro
Sheet Author
Well, if nothing else, you can probably style your checkbox as the button.