[LON-CAPA-cvs] cvs: loncom /interface lonhelper.pm
foxr
lon-capa-cvs@mail.lon-capa.org
Thu, 06 Apr 2006 22:30:53 -0000
foxr Thu Apr 6 18:30:53 2006 EDT
Modified files:
/loncom/interface lonhelper.pm
Log:
Added relatedvalue and relateddefault attributes to <choice> in <choices>
element. This allows a text input to be associated with a choice.
e.g. <choice computer="1" relatedvalue="somevariable" relateddefault="42"> ...
The value in the text box goes into $helper->{VARS}->{somevariable}
and the text box is initially displaying 42.
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.135 loncom/interface/lonhelper.pm:1.136
--- loncom/interface/lonhelper.pm:1.135 Sun Mar 19 18:09:20 2006
+++ loncom/interface/lonhelper.pm Thu Apr 6 18:30:52 2006
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.135 2006/03/19 23:09:20 albertel Exp $
+# $Id: lonhelper.pm,v 1.136 2006/04/06 22:30:52 foxr Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1069,6 +1069,16 @@
the choice is not multichoice. This will override the nextstate
passed to the parent C<choices> tag.
+<choice> may optionally contain a 'relatedvalue' attribute, which
+if present will cause a text entry to appear to the right of the
+selection. The value of the relatedvalue attribute is a variable
+into which the text entry will be stored e.g.:
+<choice computer='numberprovided" relatedvalue="num">Type the number in:</choice>
+
+<choice> may contain a relatededefault atribute which, if the
+relatedvalue attribute is present will be the initial value of the input
+box.
+
=back
To create the choices programmatically, either wrap the choices in
@@ -1159,10 +1169,12 @@
my $computer = $token->[2]{'computer'};
my $human = &mt(&Apache::lonxml::get_all_text('/choice',
$parser));
- my $nextstate = $token->[2]{'nextstate'};
- my $evalFlag = $token->[2]{'eval'};
+ my $nextstate = $token->[2]{'nextstate'};
+ my $evalFlag = $token->[2]{'eval'};
+ my $relatedVar = $token->[2]{'relatedvalue'};
+ my $relatedDefault = $token->[2]{'relateddefault'};
push @{$paramHash->{CHOICES}}, [&mtn($human), $computer, $nextstate,
- $evalFlag];
+ $evalFlag, $relatedVar, $relatedDefault];
return '';
}
@@ -1272,14 +1284,20 @@
}
$result .= qq{id="id$id"};
my $choiceLabel = $choice->[0];
- if ($choice->[4]) { # if we need to evaluate this choice
+ if ($choice->[3]) { # if we need to evaluate this choice
$choiceLabel = "sub { my $helper = shift; my $state = shift;" .
$choiceLabel . "}";
$choiceLabel = eval($choiceLabel);
$choiceLabel = &$choiceLabel($helper, $self);
}
$result .= "/></td><td> ".qq{<label for="id$id">}.
- $choiceLabel. "</label></td></tr>\n";
+ $choiceLabel. "</label></td>";
+ if ($choice->[4]) {
+ $result .='<td><input type="text" size="5" name="'
+ .$choice->[4].'.forminput" value="'
+ .$choice->[5].'" /></td>';
+ }
+ $result .= "</tr>\n";
}
$result .= "</table>\n\n\n";
$result .= $buttons;
@@ -1313,6 +1331,10 @@
$helper->changeState($choice->[2]);
}
}
+ if ($choice->[4]) {
+ my $varname = $choice->[4];
+ $helper->{'VARS'}->{$varname} = $env{'form.'."$varname.forminput"};
+ }
}
return 1;
}