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

bowersj2 lon-capa-cvs@mail.lon-capa.org
Thu, 08 May 2003 20:10:49 -0000


bowersj2		Thu May  8 16:10:49 2003 EDT

  Modified files:              
    /loncom/interface	lonhelper.pm 
  Log:
  Add the ability for <choices> elements to accept no choices at all without
  erroring out.
  
  
Index: loncom/interface/lonhelper.pm
diff -u loncom/interface/lonhelper.pm:1.25 loncom/interface/lonhelper.pm:1.26
--- loncom/interface/lonhelper.pm:1.25	Thu May  8 15:52:43 2003
+++ loncom/interface/lonhelper.pm	Thu May  8 16:10:49 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # .helper XML handler to implement the LON-CAPA helper
 #
-# $Id: lonhelper.pm,v 1.25 2003/05/08 19:52:43 bowersj2 Exp $
+# $Id: lonhelper.pm,v 1.26 2003/05/08 20:10:49 bowersj2 Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -960,6 +960,10 @@
 <choices> takes an attribute "multichoice" which, if set to a true
 value, will allow the user to select multiple choices.
 
+<choices> takes an attribute "allowempty" which, if set to a true 
+value, will allow the user to select none of the choices without raising
+an error message.
+
 B<SUB-TAGS>
 
 <choices> can have the following subtags:
@@ -1049,6 +1053,7 @@
     $paramHash->{'variable'} = $token->[2]{'variable'} if (!defined($paramHash->{'variable'}));
     $helper->declareVar($paramHash->{'variable'});
     $paramHash->{'multichoice'} = $token->[2]{'multichoice'};
+    $paramHash->{'allowempty'} = $token->[2]{'allowempty'};
     $paramHash->{CHOICES} = [];
     return '';
 }
@@ -1193,7 +1198,7 @@
     my $self = shift;
     my $chosenValue = $ENV{'form.' . $self->{'variable'} . '.forminput'};
 
-    if (!defined($chosenValue)) {
+    if (!defined($chosenValue) && !$self->{'allowempty'}) {
         $self->{ERROR_MSG} = "You must choose one or more choices to" .
             " continue.";
         return 0;