use warnings; use strict; package Jifty::Web::Form::Field::Checkbox; use base qw/Jifty::Web::Form::Field/; __PACKAGE__->mk_accessors(qw/checked value/); =head1 NAME Jifty::Web::Form::Field::Checkbox - Add checkboxes to your forms =head1 METHODS =head2 accessors Provide C and C accessors, in addition to L's default accessors. C defaults to "1". =cut sub accessors { shift->SUPER::accessors(), 'checked' , 'value' } =head2 render_widget Renders the checkbox widget. =cut sub render_widget { my $self = shift; my $field = qq!\n!; $field .= qq!title); $field .= qq! name="@{[ $self->input_name ]}"!; $field .= qq! id="@{[ $self->element_id ]}"!; $field .= qq! value="@{[$self->value ||1]}"!; $field .= $self->_widget_class; $field .= qq! checked="checked"! if ($self->checked or $self->current_value); $field .= $self->javascript; $field .= qq! />\n!; Jifty->web->out($field); ''; } =head2 render_value Renders value as a checkbox widget. =cut sub render_value { my $self = shift; my $field .= qq!title); $field .= qq! id="@{[ $self->element_id ]}"!; $field .= qq! value="@{[$self->value ||1]}"!; $field .= $self->_widget_class; $field .= qq! checked="checked"! if ($self->checked or $self->current_value); $field .= qq! disabled="disabled" readonly="readonly"!; $field .= qq! />\n!; Jifty->web->out($field); return ''; } =head2 javascript_preempt By default, javascript (such as onclick handlers) should not actually prevent browsers from placing the checkmark in the checkbox. =cut sub javascript_preempt { return 0; } 1;