3 CXGN::Page::Form::MultiSelect;
7 Implements a static (non-editable) multiple-selection list on a static form. For more information, see L<CXGN::Page::Form>.
9 Currently a MultiSelect displays as a multiple-selection drop-down menu. It could also be a series of checkboxes with the same field name;
10 implement that yourself if you need it.
19 use CXGN
::Page
::Form
::ElementI
;
21 package CXGN
::Page
::Form
::MultiSelect
;
23 use base qw
/ CXGN::Page::Form::ElementI /;
30 Args: a hashref with the following keys:
31 display_name (name of the field for display purposes)
32 field_name (name of the variable)
33 choices (an arrayref of IDs for the strings to be shown)
34 labels (an arrayref of strings to be shown)
35 contents (an arrayref of values that will be evaluated as Booleans to get the initial selection)
36 object (the object this field maps to)
37 getter (the getter function for this field in the object)
38 setter (the setter function for this field in the object)
48 my $self = $class->SUPER::new
(%params);
49 #store the parameters that aren't handled by our superclass
50 foreach my $param (qw(choices labels))
52 my $set_func = "set_$param";
53 $self->$set_func($params{$param});
72 #render as a comma-separated list of labels
73 my @selected_labels = ();
74 for(my $i = 0; $i < scalar($self->get_choice_array()); $i++)
76 if($self->is_selected($i))
78 push @selected_labels, $self->get_label($i);
81 return join(", ", @selected_labels);
84 =head2 set_from_external
86 Args: string with all values for this field separated by \0
92 my ($self, $value_string) = @_;
93 my %values = map {$_ => 1} split(/\0/, $value_string); #map only values that appear to 1
94 my @choices = $self->get_choice_array();
95 for(my $i = 0; $i < scalar(@choices); $i++)
97 if($values{$choices[$i]})
99 $self->set_selected($i, 1);
113 return $self->{choices
}->[$i];
116 =head2 get_choice_array
118 Ret: array (not arrayref) of choices
125 return @
{$self->{choices
}};
130 Args: arrayref of choices
136 my ($self, $choices) = @_;
137 $self->{choices
} = $choices;
149 return $self->{labels
}->[$i];
154 Args: arrayref of labels
160 my ($self, $labels) = @_;
161 $self->{labels
} = $labels;
173 return $self->{contents
}->[$i];
178 Args: index, an expression that will be evaluated in Boolean context
184 my ($self, $i, $val) = @_;
185 $self->{contents
}->[$i] = ($val ?
1 : 0);