[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 24 Sep 2004 19:49:12 -0000


matthew		Fri Sep 24 15:49:12 2004 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  use <label> around radio & checkbox inputs.  Only on those inputs whose
  labels are generated in the helper, not navmaps, so inputs where you select
  a resource or folder are not affected.
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.86 loncom/interface/lonhelper.pm:1.87
--- loncom/interface/lonhelper.pm:1.86	Thu Aug 12 03:45:03 2004
+++ loncom/interface/lonhelper.pm	Fri Sep 24 15:49:12 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.86 2004/08/12 07:45:03 albertel Exp $
+# $Id: lonhelper.pm,v 1.87 2004/09/24 19:49:12 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1174,6 +1174,13 @@
     return '';
 }
 
+{
+    # used to generate unique id attributes for <input> tags. 
+    # internal use only.
+    my $id = 0;
+    sub new_id { return $id++; }
+}
+
 sub render {
     my $self = shift;
     my $var = $self->{'variable'};
@@ -1256,6 +1263,7 @@
     my $type = "radio";
     if ($self->{'multichoice'}) { $type = 'checkbox'; }
     foreach my $choice (@{$self->{CHOICES}}) {
+        my $id = &new_id();
         $result .= "<tr>\n<td width='20'>&nbsp;</td>\n";
         $result .= "<td valign='top'><input type='$type' name='$var.forminput'"
             . "' value='" . 
@@ -1264,6 +1272,7 @@
         if ($checkedChoices{$choice->[1]}) {
             $result .= " checked ";
         }
+        $result .= qq{id="$id"};
         my $choiceLabel = $choice->[0];
         if ($choice->[4]) {  # if we need to evaluate this choice
             $choiceLabel = "sub { my $helper = shift; my $state = shift;" .
@@ -1271,7 +1280,8 @@
             $choiceLabel = eval($choiceLabel);
             $choiceLabel = &$choiceLabel($helper, $self);
         }
-        $result .= "/></td><td> " . &mtn($choiceLabel) . "</td></tr>\n";
+        $result .= "/></td><td> ".qq{<label for="$id">}.
+            &mtn($choiceLabel). "</label></td></tr>\n";
     }
     $result .= "</table>\n\n\n";
     $result .= $buttons;
@@ -2375,6 +2385,13 @@
 
 sub end_filefilter { return ''; }
 
+{ 
+    # used to generate unique id attributes for <input> tags. 
+    # internal use only.
+    my $id=0;
+    sub new_id { return $id++;}
+}
+
 sub render {
     my $self = shift;
     my $result = '';
@@ -2513,14 +2530,16 @@
             if ($status eq 'Published' && $helper->{VARS}->{'construction'}) {
                 $onclick = 'onclick="a=1" ';
             }
+            my $id = &new_id();
             $result .= '<tr><td align="right"' . " bgcolor='$color'>" .
                 "<input $onclick type='$type' name='" . $var
-            . ".forminput' value='" . HTML::Entities::encode($fileName,'<>&"').
+            . ".forminput' ".qq{id="$id"}." value='" . HTML::Entities::encode($fileName,'<>&"').
                 "'";
             if (!$self->{'multichoice'} && $choices == 0) {
                 $result .= ' checked';
             }
-            $result .= "/></td><td bgcolor='$color'>" . $file . "</td>" .
+            $result .= "/></td><td bgcolor='$color'>".
+                qq{<label for="$id">}. $file . "</label></td>" .
                 "<td bgcolor='$color'>$title</td>" .
                 "<td bgcolor='$color'>$status</td>" . "</tr>\n";
             $choices++;