added sol100 and chado cvterm pages to validate_all.t
[sgn.git] / lib / CXGN / Page / Form / RadioList.pm
blob666cac94f047d9f109b1f3547fe2a91d694e965c
1 =head1 NAME
3 CXGN::Page::Form::RadioList;
5 =head1 DESCRIPTION
7 Implements a static (non-editable) list of radio buttons on a static form. For more information, see L<CXGN::Page::Form>.
9 =head1 AUTHOR(S)
11 Evan Herbst
13 =cut
15 use strict;
16 use CXGN::Page::Form::ElementI;
18 package CXGN::Page::Form::RadioList;
20 use base qw/ CXGN::Page::Form::ElementI /;
22 =head2 new
24 Usage: don't currently make use of the 'id' parameter, unlike other form fields
25 Desc:
26 Ret:
27 Args: a hashref with the following keys:
28 display_name (name of the field for display purposes)
29 field_name (name of the variable)
30 id_prefix (a string to be prepended to the choices to get radio-button element IDs)
31 choices (a listref of values for the buttons to be shown)
32 labels (a listref of labels for the buttons to be shown)
33 contents (the current value of the field; can be empty)
34 object (the object this field maps to)
35 getter (the getter function for this field in the object)
36 setter (the setter function for this field in the object)
37 Side Effects:
38 Example:
40 =cut
42 sub new
44 my $class = shift;
45 my %params = @_;
46 my $self = $class->SUPER::new(%params);
47 #store the parameters that aren't handled by our superclass
48 foreach my $param (qw(choices labels id_prefix))
50 my $set_func = "set_$param";
51 $self->$set_func($params{$param});
53 return $self;
56 =head2 render
58 Usage:
59 Desc:
60 Ret:
61 Args:
62 Side Effects:
63 Example:
65 =cut
67 sub render
69 my $self = shift;
70 my $html = "<ul>";
71 for(my $i = 0; $i < scalar($self->get_choice_array()); $i++)
73 if($self->get_contents() eq $self->get_choice($i))
75 $html .= "<li> &raquo;&nbsp;" . $self->get_label($i) . "&nbsp;&laquo; </li>";
77 else
79 $html .= "<li>" . $self->get_label($i) . "</li>";
82 return $html . "</ul>";
85 =head2 get_id_prefix
87 =cut
89 sub get_id_prefix
91 my $self = shift;
92 return $self->{id_prefix};
95 =head2 get_choice
97 Args: choice index
99 =cut
101 sub get_choice
103 my ($self, $i) = @_;
104 return $self->{choices}->[$i];
107 =head2 get_choice_array
109 Ret: array (not arrayref) of choices
111 =cut
113 sub get_choice_array
115 my $self = shift;
116 return @{$self->{choices}};
119 =head2 get_label
121 Args: label index
123 =cut
125 sub get_label
127 my ($self, $i) = @_;
128 return $self->{labels}->[$i];
131 =head2 set_id_prefix
133 Args: string
135 =cut
137 sub set_id_prefix
139 my ($self, $prefix) = @_;
140 $self->{id_prefix} = $prefix;
143 =head2 set_choices
145 Args: arrayref of choices
147 =cut
149 sub set_choices
151 my ($self, $choices) = @_;
152 $self->{choices} = $choices;
155 =head2 set_labels
157 Args: arrayref of labels
159 =cut
161 sub set_labels
163 my ($self, $labels) = @_;
164 $self->{labels} = $labels;
167 return 1;