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

Disable a Checkbox upon selection?

Does anyone know, is it possible to make a checkbox "Disabled" when it is selected? I want to make a checkbox that cannot be unchecked after it is selected... Thanks in advance.
1596896071

Edited 1596896087
vÍnce
Pro
Sheet Author
I don't think so.   But you could probably make use of  display:none  with css if the input is checked. example (untested); <input type="checkbox" name="attr_foo" value="1" class="foo-flag" /> input[type="checkbox"].sheet-foo-flag:checked {display:none;} Not sure of your use case for such a checkbox, but you might consider having an option on a settings page that can override if necessary. (note: Technically speaking I think a checkbox is considered "disabled" if it is unchecked.  By default it assigned a value="1" if checked.  This can be reversed if you provide a value="0".  But it sounds like you really just want to hide the checkbox as an option.) Cheers
1596897185
GiGs
Pro
Sheet Author
API Scripter
First thing I'd suggest: you need some way to uncheck the checkbox if it is disabled. Because players will make a mistake and check it by accident. If there's no way to undo it, that's bad. But on to the actual question: If you want the checkbox to remain visible, but disabled, two approaches come to mind: Use the CSS Swap Areas trick (see CSS Wizardry page): You have two checkboxes, one disabled, one not. The disabled one is hidden. When the checkbox is checked, the non-disabled checkbox is hidden, and the disabled one takes its place. The second method is a sheet worker: you check the checkboxes status when clicked. Using eventInfo (see wiki on sheet workers) you can get the previous state before being clicked. If the prev state is checked, it means the player is trying to uncheck the checkbox. So you have the sheetworker just recheck it. That way the player can never uncheck it.
1596899217
Jakob
Sheet Author
API Scripter
Third option: using CSS to toggle a transparent div that floats on top of the checkbox and covers it. Disadvantage is that a crafty user may still be able to tab into the checkbox and uncheck it using the keyboard :). But +1 to Gigs' caveat, you need some way for the user to reset the state if they toggle it by accident.
1596918059
Finderski
Pro
Sheet Author
Compendium Curator
Fourth option, use a radio button instead of a checkbox.  And another +1 to GiGs' caveat.
1596935049

Edited 1596942294
Ray
Pro
Thanks everyone, I am already working on the "swap visible areas" method which I found in the CSS Wizardry as per Gigs' suggestion. Having trouble with this atm, but will see how it goes. Cheers  :) p.s. Good advice also on the problem of not being able to uncheck the box...I will think on that one.  ;)