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

Replacing checkboxes with radio buttons without changing the attribute name

1470012747
Phalanks
Pro
Sheet Author
I'm working on replacing some long rows of checkboxes with left fillable radio buttons. Problem is, I can't seem to find a way to do it while keeping the attribute name the same. See the below code snippet. Any one know of a way to do it? Replace This <div class="sheet-row">     <div class="sheet-col"><label for="attr_recovery" class="sheet-recovery">Recovery:</label></div>     <input type="checkbox" name="attr_recovery1" class="sheet-recovery sheet-check-first"><span></span>     <input type="checkbox" name="attr_recovery2" class="sheet-recovery sheet-check"><span></span>     <input type="checkbox" name="attr_recovery3" class="sheet-recovery sheet-check"><span></span>     <input type="checkbox" name="attr_recovery4" class="sheet-recovery sheet-check"><span></span>     <input type="checkbox" name="attr_recovery5" class="sheet-recovery sheet-check"><span></span>     <input type="checkbox" name="attr_recovery6" class="sheet-recovery sheet-check"><span></span>     <input type="checkbox" name="attr_recovery7" class="sheet-recovery sheet-check"><span></span>     <input type="checkbox" name="attr_recovery8" class="sheet-recovery sheet-check"><span></span> </div> With This <div class="sheet-row">     <div class="sheet-col"><label for="attr_recovery" class="sheet-recovery">Recovery:</label></div>     input type="radio" class="sheet-recovery sheet-leftradio sheet-zero" name="attr_recovery" value="0" checked="checked" /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=1 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=2 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=3 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=4 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=5 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=6 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=7 /><span></span>     <input type="radio" class="sheet-recovery sheet-leftradio" name="attr_recovery" value=8 /><span></span> </div>
1470013040
Lithl
Pro
Sheet Author
API Scripter
You would have to use a sheet worker script to set the value of the radio button based on the value of the old checkbox.
1470015501

Edited 1470016260
Phalanks
Pro
Sheet Author
Perfect, thank you for the guidance! Is there anyway to have a "run once" worker script? I suppose I could make a boolean type attribute, check it on sheet open and only run it if it's 0.
1470017463
Lithl
Pro
Sheet Author
API Scripter
Phalanks said: Is there anyway to have a "run once" worker script? I suppose I could make a boolean type attribute, check it on sheet open and only run it if it's 0. That is exactly how you would have to do it.
I'm doing this by doing a getAttr on all of the original checkboxes and counting the ones that are set to "on". &nbsp;If the total is greater than zero, I turn them all off and set the value of the radio to the total. &nbsp;Each time it runs after the initial fix, it'll just do the getAttr and the greater-than comparison, so it should be low impact. &nbsp;Here's my code: &nbsp;<a href="https://gist.github.com/mhglover/c164dab0661dade9491ca770f5e9e59f" rel="nofollow">https://gist.github.com/mhglover/c164dab0661dade9491ca770f5e9e59f</a>