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

Help with radio/checkboxes in a custom sheet?

Heyo, it's me again, back at it with the not knowing what I'm doing o/


I'll keep it brief. I want something like this in my character sheet:


And by "something" I mean basically just that. Obviously I can make a mock-up really easy in a Googledoc, but I want a functioning version on the sheet :(


The idea is that there are 4 sections, each with 2 columns containing 10 of these traits (5 in each column), and each trait is displayed as:
[Title] : [Single checkbox] [4 radio buttons that fill to the left] [Single checkbox]

I've been trying to duct tape codes for the radio buttons and checkboxes together, but I'm reaching a point where it's snowballing into more issues than I know how to fix. Namely: in total, this will account for 80 of these individual traits, and I'm struggling to figure out how to give those inputs unique attributes without turning the overall code into a massive wall of repetitive text. I also can't get them to sit where I want them to physically, as the radio buttons only want to be aligned vertically. All in all, it's getting a bit chaotic, so I figured I'd ask for assistance because surely there has to be a more intuitive way to go about this lmao


Disclaimer: I'm not very code-savvy, I'm just occasionally able to piece things together to get what I want. So please forgive my ignorance here!

Thanks in advance!

April 28 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

The picture isnt showing up.


GiGs said:

The picture isnt showing up.


Oh, that's weird. It shows up for me. 

https://i.gyazo.com/e9a5bfe49e9ec04d4e409c3ad65f508e.png


Try that?


April 28 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

Do you need all the boons and banes? this looks like a perfect place for a repeating section. 

If you post the code (HTML and CSS) for the banes and boons section you have now (can be partial as long as the start and end are includes - can cut out some of the rows), we can help you.


GiGs said:

Do you need all the boons and banes? this looks like a perfect place for a repeating section. 

If you post the code (HTML and CSS) for the banes and boons section you have now (can be partial as long as the start and end are includes - can cut out some of the rows), we can help you.


I don't have any code for it at the moment; the screenshot is from the mock-up I did in a GoogleDoc. 

I'm not entirely familiar, but wouldn't a repeating section be the sort of thing that comes with an "Add" / "Modify" button? The entire list is meant to be a consistent part of the character sheet, so if that's what you're referring to, I'm not sure it's what I'm looking for. But I could definitely be misunderstanding!

April 28 (5 years ago)

No, you've got it right. Repeating sections do that. I find them very useful.
One way I've used them is to make a "blank" sheet for all players which contains a previously generated list of repeating sections.
That way you get the functionality and ease of coding the repeating section, but you don't need to make your players build the list each time.

Then you duplicate your reference blank sheet for each new player. It's how I do it.


Tuck S. said:

No, you've got it right. Repeating sections do that. I find them very useful.
One way I've used them is to make a "blank" sheet for all players which contains a previously generated list of repeating sections.
That way you get the functionality and ease of coding the repeating section, but you don't need to make your players build the list each time.

Then you duplicate your reference blank sheet for each new player. It's how I do it.


Thanks for that clarification!

My concern is more that these stats will be fluctuating each game, so it's important that they're all available on the character sheet, and there's not any modifying or removing (or adding to) them. I'm just struggling to figure out how to code each individual trait (the layout of the radio buttons and check boxes, keeping all 80 different traits unique stats visavi attributes, etc). 

April 28 (5 years ago)

You're dealing with a lot of attributes, but it's manageable The only suggestion I'm qualified to make is that you make sure you keep your attribute names very clear,

"attr_cboon_aether_resistant" for example..

April 28 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

If you plan to have all the banes and boons on every character, without using a repeating section, you will have to create 80+ attributes, and do a lot of copying and editing of the same sections. 

If you put them in a repeating section, you can create just one set of boxes (the boxes needed for a single set boon or bane), and then each time you click add, the player can add another one. The radio boxes will be automatically segmented by bane or boon, so you wont have to worry about that.

You could create a dropdown with a list of all the banes or boons, so that players dont have to type them in.


If all characters need all of the boons and banes on their sheet, this approach isnt a good one. But if they don't, they will be a really easy way to make the code.


GiGs said:

If you plan to have all the banes and boons on every character, without using a repeating section, you will have to create 80+ attributes, and do a lot of copying and editing of the same sections. 

If you put them in a repeating section, you can create just one set of boxes (the boxes needed for a single set boon or bane), and then each time you click add, the player can add another one. The radio boxes will be automatically segmented by bane or boon, so you wont have to worry about that.

You could create a dropdown with a list of all the banes or boons, so that players dont have to type them in.


If all characters need all of the boons and banes on their sheet, this approach isnt a good one. But if they don't, they will be a really easy way to make the code.


Yeah, unfortunately, the latter is true; all characters need all boons and banes. Honestly, I don't necessarily mind having a giant wall of code for all of them, I'm just struggling right now to be able to code the buttons themselves. I can't get the radio buttons / check boxes from this page's resources to play nice in this setup, which is what prompted me to give up ask for help lmao

April 29 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

Okay, so a giant wall of repetitive code it is :)

We can help get it sorted, layout wise. But you'll have to post the html and css you are trying for the banes and boons (just one bane or boon will be enough, but the complete code for that section), and then we can show you ow to get it working.


GiGs said:

Okay, so a giant wall of repetitive code it is :)

We can help get it sorted, layout wise. But you'll have to post the html and css you are trying for the banes and boons (just one bane or boon will be enough, but the complete code for that section), and then we can show you ow to get it working.


Thank you!!

I actually ended up scrapping it all when I was seeing it was a losing battle, so let me take a minute here and try to more or less reassemble what I was doing.

I was pretty much exclusively taking code from this thread. I tried piecing them together something like this;
HTML;

<input type="hidden" class="direction" name="attr_direction" value="down" />
<button type="action" name="act_direction_toggle" class="direction">
  <span class="down">▼</span>
  <span class="right">►</span>
</button>


<div class="radios"> <input type="hidden" class="radio" name="attr_level" value="1" /> <button type="action" name="act_level_1" class="radio radio-1"> <span class="checked"></span> </button> <button type="action" name="act_level_2" class="radio radio-2"> <span class="checked"></span> </button> <button type="action" name="act_level_3" class="radio radio-3"> <span class="checked"></span> </button> <button type="action" name="act_level_4" class="radio radio-4"> <span class="checked"></span> </button> <button type="action" name="act_level_5" class="radio radio-5"> <span class="checked"></span> </button> </div>


<input type="hidden" class="direction" name="attr_direction" value="down" /> <button type="action" name="act_direction_toggle" class="direction"> <span class="down">▼</span> <span class="right">►</span> </button>

HTML script;

<script type="text/worker">
  
    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"
      });
    });
  });


const levelRadioValues = ["1","2","3","4","5"];
  levelRadioValues.forEach(function(value) {
    on(`clicked:level_${value}`, function() {
      setAttrs({
        ["level"]: value
      });
    });
  });


</script>

CSS;

/* Clear default button styling */
button.sheet-direction {
  margin: 0;
  overflow: visible;
  text-transform: none;
  border-style: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

/* Hide the section(s) that do not match the attribute value */
input.sheet-direction:not([value="down"]) + button.sheet-direction > span.sheet-down {
  display: none;
}
input.sheet-direction:not([value="right"]) + button.sheet-direction > span.sheet-right {
  display: none;
}



/* Configure a container for the radio buttons. */
.sheet-radios {
  display: flex;
  align-items: center;
}

/* Configure the button styling. This example makes it look like a radio. */
button.sheet-radio {
  padding: 0;
  border: solid 1px #a8a8a8;
  cursor: pointer;

  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
}
button.sheet-radio > span.sheet-checked {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: buttontext;
}

/* Hide the "checked" section of the radio if the attribute value does not match the radio */
input.sheet-radio:not([value="1"]) ~ button.sheet-radio-1 > span.sheet-checked,
input.sheet-radio:not([value="2"]) ~ button.sheet-radio-2 > span.sheet-checked,
input.sheet-radio:not([value="3"]) ~ button.sheet-radio-3 > span.sheet-checked,
input.sheet-radio:not([value="4"]) ~ button.sheet-radio-4 > span.sheet-checked,
input.sheet-radio:not([value="5"]) ~ button.sheet-radio-5 > span.sheet-checked {
  display: none;
}

Messing with the formatting and all, I have this screenshot of what I sssssort of accomplished;

(In case the image doesn't work again, direct link is here)

But the issue I was having was that even though it kind of looked how I wanted (that top left one notwithstanding, I forget what I was trying to tweak there but it clearly wasn't working lmao), the functionality wasn't happening. Sometimes the radio buttons didn't work, sometimes the "check boxes" (which I replaced with a little image) didn't work, but mostly, I couldn't figure out where to assign attributes to them so they were all independent. So I'd toggle something on one of them, and all of them would echo the exact same input, which obviously won't do. 

But if I could get it looking like those three normal panels, and actually functioning, that's really all I'm after.

Thanks again!

April 30 (5 years ago)
GiGs
Pro
Sheet Author
API Scripter

There's a lot to take in there, and I;m not an expert on CSS so I hope  someone else chimes in on that. In your sheet worker,

const levelRadioValues = ["1","2","3","4","5"];
  levelRadioValues.forEach(function(value) {
    on(`clicked:level_${value}`, function() {
      setAttrs({
        ["level"]: value
      });
    });
  });

setAttrs isnt quite right. it can be either

      setAttrs({
        "level": value
      });
or
      setAttrs({
        level: value
      });

If your issue is CSS related, this wont fix it, but its worth a try.


GiGs said:


Sorry for disappearing for a bit, life got wild.

Made those changes! But still, even with those changes, the aforementioned code only gets me this:

 (If image doesn't work > click)

Is there a good way to get the checkboxes (shown there as arrows) to be nice and in line at the start and the end of the radio buttons?

Also, in this code--

<input type="hidden" class="direction" name="attr_direction" value="down" />
<button type="action" name="act_direction_toggle" class="direction">
  <span class="down">▼</span>
  <span class="right">►</span>
</button>

--where do I specify the unique attribute of each individual stat? I think last time I tried renaming the name="attr_direction" part, but that didn't solve the problem of every time the checkbox was "ticked", it made every single checkbox on the page tick instead of just that one.