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

Problem: Show checkboxes depending on an attribute value with additional functions

1630738681
Rondragos
Pro
Sheet Author
I'm writing a custom WoD Sheet for a multi-splash-crossover. There I will have multiple "pools" of temporary points, which I want to fill from the left, so if the 3rd box is checked, the 1st and 2nd should also be checked. This works and is all I need for most pools, that go to a maximum of 10 with a similiar behaving permanent value right above like this: (And yes it is based on the V20 sheet by Matt Zaldivar) The Problem is especially with the Blood Pool: It should be able to go up to 50, but most players will have only the ability to have 10 to 15 points, others only 2 to 3, so I want only show them this amount of boxes, based on the amount they put into a number field. The problem is - the boxes disappear, but don't reappear. There is quite a lot of code, I hope I don't miss something that messes with it and don't post too much: html: (yeah until now there are 10 points, because I wanted to confirm it works before I copy, paste and change the value up to 50) <div class="line-heading"><span class="line-heading">Blood Pool</span></div>     <div class="pool-row"> <input type="number" name="attr_BloodPool_max" value="10"/>     </div>     <div class="pool-row zero blood"> <input type="hidden" name="attr_BloodPool_max" />         <input type="radio" name="attr_bloodpool" value="0" class="zero trait-check" checked /><span></span>         <input type="radio" name="attr_bloodpool" value="1" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="2" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="3" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="4" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="5" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="6" class="temp trait-check"/><span></span>        <input type="radio" name="attr_bloodpool" value="7" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="8" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="9" class="temp trait-check"/><span></span>         <input type="radio" name="attr_bloodpool" value="10" class="temp trait-check"/><span></span> </div> And the css up until now: /*Radios Fill to the left*/ /* Hide actual dot*/ input.trait-radio[type="radio"], input.zero[type="radio"], input.temp[type="radio"] { opacity: 0; width: 16px; height: 16px; position: relative; left: 6px; margin: -10px; cursor: pointer; z-index: 1; } /* Styles common to fake dot*/ input.trait-radio[type="radio"] + span::before, input.zero[type="radio"] + span::before, input.temp[type="radio"] + span::before{ margin-right: 1px; border: solid 1px #a8a8a8; line-height: 14px; text-align: center; display: inline-block; vertical-align: middle; content: ""; width: 12px; height: 12px; -moz-border-radius: 50%; -webkit-border-radius: 50%; border-radius: 50%; -moz-box-shadow: 0 0 2px #ccc; -webkit-box-shadow: 0 0 2px #ccc; box-shadow: 0 0 2px #ccc; background: #000000; } /* Remove dot from all radios _after_ selected one */ input.trait-radio[type="radio"]:checked ~ input.trait-radio[type="radio"] + span::before, input.zero[type="radio"]:checked ~ input[type="radio"] + span::before, input.temp[type="radio"]:checked ~ input[type="radio"] + span::before { content: ""; background: #f6f6f6; background: -moz-radial-gradient(#f6f6f6, #dfdfdf); background: -webkit-radial-gradient(#f6f6f6, #dfdfdf); background: -ms-radial-gradient(#f6f6f6, #dfdfdf); background: -o-radial-gradient(#f6f6f6, #dfdfdf); background: radial-gradient(#f6f6f6, #dfdfdf); } /*Special radios*/ input.temp.trait-check+span::before { content: "X"; width: 12px; height: 12px; font-size: 12px; -moz-border-radius: 0%; -webkit-border-radius: 0%; border-radius: 0%; background: #f6f6f6; background: -moz-radial-gradient(#f6f6f6, #dfdfdf); background: -webkit-radial-gradient(#f6f6f6, #dfdfdf); background: -ms-radial-gradient(#f6f6f6, #dfdfdf); background: -o-radial-gradient(#f6f6f6, #dfdfdf); background: radial-gradient(#f6f6f6, #dfdfdf); } input.zero.trait-check:checked + span::before { opacity: 0; } input.zero.trait-check:hover + span::before { opacity: 1; } input.zero.trait-check + span::before { opacity: .25; font-size: 12px; content: "X"; background: #f6f6f6; background: -moz-radial-gradient(#f6f6f6, #dfdfdf); background: -webkit-radial-gradient(#f6f6f6, #dfdfdf); background: -ms-radial-gradient(#f6f6f6, #dfdfdf); background: -o-radial-gradient(#f6f6f6, #dfdfdf); background: radial-gradient(#f6f6f6, #dfdfdf); } So to hide the "checkboxes" I startet code like this (its not complete, because I first wanted to confirm it works before I type it up to 50 times (or even 10 first)) CSS: div.blood > input.temp[type="radio"] + span::before { display: none; } div.blood > input[type="hidden"][value="1"] ~ input.temp[type="radio"]:nth-of-type(-n+1) + span::before { display: inline-block; } div.blood > input[type="hidden"][value="2"] ~ input.temp[type="radio"]:nth-of-type(-n+2) + span::before { display: inline-block; } I'm not a very experienced programmer, but as far as I understand it, it should work... is there a small mistake I'm missing or is my approach wrong?
1630766517
GiGs
Pro
Sheet Author
API Scripter
I havent looked at your code (too early in my day to look at CSS!), but the way I would do it is pretty simple: Have the blood boxes grouped in divs according to generation, 1-10 in one div, and then the boxes for each extra generation getting another div. (I cant remember what the groups are). And just before each div a hidden input which starts with a value of 0, and might sometimes be 1. That input will have a unique css style. Then a CSS rule that shows the div the input has a value of 1. Finally a sheet worker which responds to the changing generation or max blood pool, which sets those hidden inputs to 0 or 1 as appropriate, and also sets the blood pools in those sections to value 0 if they are over the max blood pool. (And they can never be changed manually, because they'll be hidden.) That should solve the issue, if I've understood it.
1630775420
Rondragos
Pro
Sheet Author
Thanks for the answer. I think that would also destroy the ability to have them filled from left to right, at least as I have them (which seemed for me a lot less work than the sheetworker/action buttons method in the css wizardry page, since I use such boxes in multiple places).  Also the Generation alone wouldn't solve it. There are or maybe Ghouls in the Game with a Bloodpool of 2 + 1 per 200 years of age as well as especially nasty spirits that might possess vampire and allow them to have a flat bonus to their bloodpool without changing Generation... so a manually set Bloodpool is what I'm aiming for, to have every ability to customize.
1630775797
GiGs
Pro
Sheet Author
API Scripter
Regarding generation: I wasnt sure about that which is why i kept referring to max blood pool as an alternative. The way you describe it, a pure CSS approach might be best, but I'm not the one to help you there, Regarding the "destroy the ability to have them filled from left to right", when I do this, i use a sheet worker to fill them - yes, a CSS approach wont work. Use eventInfo or a sheet worker loop to find out which box is being checked, and fill everything below that and clear everything higher than that. The logic can be a bit flaky, because you have to check whether a box is being checked or unchecked, and decide what consistent behaviour you want to happen on an uncheck (fill up to that point, or fill up to one below that point, for example). So I have one sheet worker to handle setting the visibility of boxes, and one to handle which ones are currently checked.
1630842098

Edited 1630844319
Andreas J.
Forum Champion
Sheet Author
Translator
A hacky way to keep the "filled from left to right" would be to create separate divs that each contains the full amount of checkboxes you need, and then your simple css rule would change which div is viewed, hiding all others by default. Will result in lot of bloat in the the sheet code, So you'd have something like this: &lt;input type="hidden" name="attr_BloodPool_max" class="blood-max" value="2"&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;div class="bloodpool-track blood-2"&gt; &lt;input type="hidden" name="attr_BloodPool_max" /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="0" class="zero trait-check" checked /&gt;&lt;span&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="1" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="2" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;div class="bloodpool-track blood-3"&gt; &lt;input type="hidden" name="attr_BloodPool_max" &gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="0" class="zero trait-check" checked /&gt;&lt;span&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="1" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="2" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &lt;input type="radio" name="attr_bloodpool" value="3" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &lt;/div&gt; &nbsp;&nbsp;&nbsp;&nbsp;&lt;div class="bloodpool-track blood-4"&gt; &lt;input type="hidden" name="attr_BloodPool_max" /&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="0" class="zero trait-check" checked /&gt;&lt;span&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="1" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;input type="radio" name="attr_bloodpool" value="2" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &lt;input type="radio" name="attr_bloodpool" value="3" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &lt;input type="radio" name="attr_bloodpool" value="4" class="temp trait-check"/&gt;&lt;span&gt;&lt;/span&gt; &lt;/div&gt; div.bloodpool-track{ display: block; } div[value="2"].blood-max ~ div.blood-2, div[value="3"].blood-max ~ div.blood-3, div[value="4"].blood-max ~ div.blood-4{ display: block; } There should be no problem from extending this to 50, just gonna be a big bunch of repetition. If I'd need to use this method, I'd generate the HTML with PUG &amp; some loops. You know what, I'll give it a try, good and simple codeblock worth trying to create with PUG. Edit: I've generated the repetitive HTML &amp; CSS so one can have a bloodpool anywhere from 1 to 50. I also saved the .pug and .scss files that generated the html &amp; css, for those wanting to try that out. 26 lines of code became ~1600 lines of HTML &amp; CSS, not bad. Code can be found here: <a href="https://gist.github.com/Anduh/711e50c1d2dbbd351518a3297fdc7517" rel="nofollow">https://gist.github.com/Anduh/711e50c1d2dbbd351518a3297fdc7517</a> It an elegant way to create in-elegant code, and not sure if I'd us it myself, but should get the job done. GiGs' idea sounds better, but it would take more time for me to figure out the sheetworkers than it took for me to work with PUG &amp; SCSS...
1630863210
vÍnce
Pro
Sheet Author
I did something like this on the Forbidden Lands sheet. CSS and HTML only.&nbsp; You might not need all the features...&nbsp; I tried to cut things down to just the relevant code.&nbsp; There's a little sheet worker, but it just calcs the total, but not necessary for the hide/show/fill of the radio. This example hides the radio buttons and shows an image instead (skull) by swapping background-image.&nbsp; Skulls are only shown depending on the ability score (basically sets the max value)&nbsp; As skulls are clicked on, all skulls up to that value are also swapped to indicate damage/fatigue.&nbsp; Uses nth-of-type(n+x). Cassie helped me with this... but it eliminated a TON of extra css. &nbsp;HTML/CSS:&nbsp; <a href="https://gist.github.com/vince-roll20/0cc8057b2953887a47af060c4c65a674" rel="nofollow">https://gist.github.com/vince-roll20/0cc8057b2953887a47af060c4c65a674</a> Hope this helps.
1630864797
GiGs
Pro
Sheet Author
API Scripter
Oh yeah, that feature on the forbidden lands sheet is very pretty and functional.
A trick you could do to avoid multiple divs is to have a hidden radio button set that maps to your attr_BloodPool_max -- i.e. &lt;input type='radio' class='invisible_radio_button hide_everything_after_me' name='attr_BloodPool_max' value='10'&gt; and then use css to hide everything after a checked button of that type. It means if they enter an invalid value everything will appear, but that's a user error. Alternately, you could make those input boxes visible (or give each one a &lt;label&gt;) and delete the numeric input box.
1631099317
Rondragos
Pro
Sheet Author
Thanks for the suggestions and ideas. It should work as in the forbidden lands example and I tried it (didn't have so much time the days before) and... it doesn't work in my sheet. I'm not quite sure why, maybe some specificity issues that I can't get worked out yet. For now I lost my patience with the Problem and will live with a bunch of checkboxes in the sheet and the player having to take care of not exceeding the maximum themselves. Perhaps in a few weeks I will come back to the problem.&nbsp; When I find a solution I will report! Thanks to everybody for the support!