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

Disable a checkbow with condition

Hello.  Sorry for my english.  I have an input text numeric with min 0 and max 6.  I have 6 checkbox in the sheet after the input. I want to disabled checkbox.  Thnaks you for the help  on("change:COMNumber", function(){ getAttrs(["COMNumber"], function(values) { var number = parseInt(values.COMNumber) || 0; if(number < 6)         {             // How to disabled and uncheck COM6, the 6th checkbox ?         } }); });
1664521598

Edited 1664521815
GiGs
Pro
Sheet Author
API Scripter
First, the min and max tags don't work in roll20. To limit to those values you need a sheet worker to check the current value and reset to 0 or 6 if outside that range. Disabling the checkbox cant be done directly in the sheet worker. You can uncheck it, like this: on("change:COMNumber", function(){ getAttrs(["COMNumber"], function(values) { var number = parseInt(values.COMNumber) || 0; if(number < 6)         {             setAttrs({ COM6: 0 });         } }); }); You can't disable the checkbox, but you can hide and show elements using CSS. So, you need two copies of the checkbox, one disabled and one not disabled. Each needs different class that can be targeted in the CSS. You also need a hidden attribute, with a class of its own. Your sheet worker sets the value of this hidden input (0 or 1) in the if statement, and the class of that input is used in CSS to choose which checkbox is hidden. For example, where your checkbox is, you'd have <input type="hidden" name="attr_com6_checkbox" value="0" class="sheet-com6-toggle"> <input type="checkbox" name="attr_com6" value="1" class="sheet-disabled" disabled="true"> <input type="checkbox" name="attr_com6" value="1" class="sheet-abled"> In your CSS, you would have something like this to show or hide those checkboxes: .charsheet input.sheet-com6-toggle[value="0"] ~ input.sheet-disabled, .charsheet input.sheet-com6-toggle[value="1"] ~ input.sheet-abled { display: none; } Finally, the above sheet worker would be modified as follows: on("change:COMNumber", function(){ getAttrs(["COMNumber"], function(values) { var number = parseInt(values.COMNumber) || 0; if(number < 6)         {             setAttrs({ COM6: 0,     com6_checkbox: 0 });         } else { setAttrs({ com6_checkbox: 1 } }); });