[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Mon, 03 May 2004 16:07:18 -0000
matthew Mon May 3 12:07:18 2004 EDT
Modified files:
/loncom/interface loncommon.pm
Log:
Modified multiple_select_form to give a value instead of a name to each
option. Modified it to take a size as input.
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.190 loncom/interface/loncommon.pm:1.191
--- loncom/interface/loncommon.pm:1.190 Fri Apr 30 19:04:53 2004
+++ loncom/interface/loncommon.pm Mon May 3 12:07:18 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# a pile of common routines
#
-# $Id: loncommon.pm,v 1.190 2004/04/30 23:04:53 albertel Exp $
+# $Id: loncommon.pm,v 1.191 2004/05/03 16:07:18 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -907,21 +907,27 @@
} &get_domains;
if ($multiple) {
$domains{''}=&mt('Any domain');
- return &multiple_select_form($name,$value,%domains);
+ return &multiple_select_form($name,$value,4,%domains);
} else {
return &select_form($name,$value,%domains);
}
}
sub multiple_select_form {
- my ($name,$value,%hash)=@_;
+ my ($name,$value,$size,%hash)=@_;
my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
my $output='';
- my $size =(scalar keys %hash<4?scalar keys %hash:4);
+ if (! defined($size)) {
+ $size = 4;
+ if (scalar(keys(%hash))<4) {
+ $size = scalar(keys(%hash));
+ }
+ }
$output.="\n<select name='$name' size='$size' multiple='1'>";
- foreach (sort keys %hash) {
- $output.="<option name='$_'".
- ($selected{$_}?' selected="1"' :'').">$hash{$_}</option>\n";
+ foreach (sort(keys(%hash))) {
+ $output.='<option value="'.$_.'" ';
+ $output.='selected ' if ($selected{$_});
+ $output.='>'.$hash{$_}."</option>\n";
}
$output.="</select>\n";
return $output;