added sol100 and chado cvterm pages to validate_all.t
[sgn.git] / lib / CXGN / Page / Form / Checkbox.pm
blob6ecf69b59e1ca16344785d7843734ceb65c8031f
1 =head1 NAME
3 CXGN::Page::Form::Checkbox - a class to represent checkboxes on CXGN::Page::Form forms.
5 =head1 DESCRIPTION
7 For more information about the form framework see L<CXGN::Page::Form>. The checkbox form element consists of two classes, CXGN::Page::Form::Checkbox, which inherits from L<CXGN::Page::Form::ElementI> and represents a static (or non-editable) checkbox, and CXGN::Page::Form::EditableCheckbox , which inherits from L<CXGN::Page::Form::Checkbox> and is used on editable forms. These classes were introduced by Evan, but re-factored somewhat by Lukas. Evan introduced an additional property for the Checkbox classes, called "selected" (with accessors get_selected and set_selected). This was refactored into using the content property, which is used by all other ElementI classes to keep track of there status. If this property is set to true, the checkbox is checked; if it is false, it is unchecked. Thus, this class is perfectly compatible with all the other code that deals with ElementI, and the additional function, set_from_external(), is not strictly necessary (although it may be useful in the future for more complex user interface elements).
9 =head1 AUTHOR(S)
11 Evan Herbst
13 =head1 FUNCTIONS
15 This class overrides the following functions:
17 =cut
19 use strict;
21 package CXGN::Page::Form::Checkbox;
23 use base qw/ CXGN::Page::Form::ElementI /;
25 =head2 new
27 Usage:
28 Desc:
29 Ret:
30 Args: a hashref with the following keys:
31 display_name (name of the field for display purposes)
32 field_name (name of the form element)
33 contents (the value used when the checkbox is selected)
34 selected (whether checked; this field is evaluated in Boolean context)
35 object (the object this field maps to)
36 getter (the getter function for this field in the object)
37 setter (the setter function for this field in the object)
38 Side Effects:
39 Example:
41 =cut
43 sub new {
44 my $class = shift;
45 my $self = $class->SUPER::new(@_);
46 my %params = @_;
47 $self->set_selected($params{selected});
48 return $self;
51 =head2 render()
53 renders the checkbox as a static element.
55 =cut
57 sub render {
58 my $self = shift;
60 return $self->get_contents() ? "(yes)" : "(no)";
63 =head2 set_from_external
65 Override ElementI. This is somewhat deprecated.
67 =cut
69 # sub set_from_external
70 # {
71 # my ($self, $value) = @_;
72 # #contents should have been set in the constructor; expect value to either equal contents or be empty (as in a request string)
74 # # $self->set_selected(($value eq $self->get_contents()) ? 1 : 0);
75 # if (($value =~ /on|t|1/i)) {
76 # # $self->set_selected(1); # set selected is deprecated
77 # $self->set_contents(1);
78 # }
79 # if ($value =~ /f|0/i || !defined($value)) {
80 # #$self->set_selected(0); #set selected is deprecated
81 # $self->set_contents(0);
82 # }
84 # }
86 return 1;