3 CXGN::Page::Form::Checkbox - a class to represent checkboxes on CXGN::Page::Form forms.
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).
15 This class overrides the following functions:
21 package CXGN
::Page
::Form
::Checkbox
;
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 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)
45 my $self = $class->SUPER::new
(@_);
47 $self->set_selected($params{selected
});
53 renders the checkbox as a static element.
60 return $self->get_contents() ?
"(yes)" : "(no)";
63 =head2 set_from_external
65 Override ElementI. This is somewhat deprecated.
69 # sub set_from_external
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);
79 # if ($value =~ /f|0/i || !defined($value)) {
80 # #$self->set_selected(0); #set selected is deprecated
81 # $self->set_contents(0);