
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.
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.
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
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.
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.