2 A tristate checkbox (with three values: true, false, and null).
3 Internally, this creates a checkbox, coupled via javascript to a hidden
4 field that actually contains the value. For now, the only values these
5 can have are 1, 0, and empty. Clicking the checkbox cycles between them.
12 <SCRIPT TYPE="text/javascript">
13 function tristate_onclick() {
15 var input = checkbox.input;
16 if ( input.value == "" ) {
18 checkbox.checked = false;
19 checkbox.indeterminate = false;
20 } else if ( input.value == "0" ) {
22 checkbox.checked = true;
23 checkbox.indeterminate = false;
24 } else if ( input.value == "1" ) {
26 checkbox.checked = true;
27 checkbox.indeterminate = true
32 var tristate_boxes = [];
33 window.onload = function() { // don't do this until all of the checkboxes exist
34 %# tristates = document.getElementsByClassName('tristate'); # curse you, IE8
35 var all_inputs = document.getElementsByTagName('input');
36 for (var i=0; i < all_inputs.length; i++) {
37 if ( all_inputs[i].className == 'tristate' ) {
38 tristates.push(all_inputs[i]);
41 for (var i=0; i < tristates.length; i++) {
43 document.getElementById('checkbox_' + tristates[i].name);
44 // make sure they can find each other
45 tristate_boxes[i].input = tristates[i];
46 tristates[i].checkbox = tristate_boxes[i];
48 tristate_boxes[i].onclick = tristate_onclick;
50 if ( tristates[i].value == "" ) {
51 tristate_boxes[i].indeterminate = true
53 if ( tristates[i].value != "0" ) {
54 tristate_boxes[i].checked = true;
60 <INPUT TYPE="hidden" NAME="<% $opt{field} %>"
62 VALUE="<% $curr_value %>"
64 <INPUT TYPE="checkbox" ID="checkbox_<%$opt{field}%>" CLASS="partial">
69 # might be useful but I'm not implementing it yet
70 #my $onchange = $opt{'onchange'}
71 # ? 'onChange="'. $opt{'onchange'}. '(this)"'
74 $opt{'id'} ||= 'hidden_'.$opt{'field'};
75 my $curr_value = $opt{curr_value};
77 unless $curr_value eq '0' or $curr_value eq '1';