« Jifty/Plugin/Config/Action/Config.pm
↑ Summary
Jifty/Plugin/Authentication/Password/Action/Signup.pm »
| 1 | use warnings; | ||
| 2 | use strict; | ||
| 3 | |||
| 4 | package Jifty::Web::Form::Field::Checkbox; | ||
| 5 | |||
| 6 | use base qw/Jifty::Web::Form::Field/; | ||
| 7 | __PACKAGE__->mk_accessors(qw/checked value/); | ||
| 8 | |||
| 9 | =head1 NAME | ||
| 10 | |||
| 11 | Jifty::Web::Form::Field::Checkbox - Add checkboxes to your forms | ||
| 12 | |||
| 13 | =head1 METHODS | ||
| 14 | |||
| 15 | =head2 accessors | ||
| 16 | |||
| 17 | Provide C<checked> and C<value> accessors, in addition to | ||
| 18 | L<Jifty::Web::Form::Field>'s default accessors. C<value> defaults to | ||
| 19 | "1". | ||
| 20 | |||
| 21 | =cut | ||
| 22 | |||
| 23 | sub accessors { shift->SUPER::accessors(), 'checked' , 'value' } | ||
| 24 | |||
| 25 | =head2 render_widget | ||
| 26 | |||
| 27 | Renders the checkbox widget. | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | sub render_widget { | ||
| 32 | my $self = shift; | ||
| 33 | my $field = qq!<input type="hidden" name="@{[ $self->fallback_name ]}" value="0" />\n!; | ||
| 34 | |||
| 35 | $field .= qq!<input!; | ||
| 36 | $field .= qq! type="checkbox"!; | ||
| 37 | $field .= qq! title="@{[ $self->title ]}"! if ($self->title); | ||
| 38 | $field .= qq! name="@{[ $self->input_name ]}"!; | ||
| 39 | $field .= qq! id="@{[ $self->element_id ]}"!; | ||
| 40 | $field .= qq! value="@{[$self->value ||1]}"!; | ||
| 41 | $field .= $self->_widget_class; | ||
| 42 | $field .= qq! checked="checked"! if ($self->checked or $self->current_value); | ||
| 43 | |||
| 44 | $field .= $self->javascript; | ||
| 45 | |||
| 46 | $field .= qq! />\n!; | ||
| 47 | Jifty->web->out($field); | ||
| 48 | ''; | ||
| 49 | } | ||
| 50 | |||
| 51 | =head2 render_value | ||
| 52 | |||
| 53 | Renders value as a checkbox widget. | ||
| 54 | |||
| 55 | =cut | ||
| 56 | |||
| 57 | sub render_value { | ||
| 58 | my $self = shift; | ||
| 59 | my $field .= qq!<input type="checkbox"!; | ||
| 60 | $field .= qq! name="@{[ $self->input_name ]}"!; | ||
| 61 | $field .= qq! title="@{[ $self->title ]}"! if ($self->title); | ||
| 62 | $field .= qq! id="@{[ $self->element_id ]}"!; | ||
| 63 | $field .= qq! value="@{[$self->value ||1]}"!; | ||
| 64 | $field .= $self->_widget_class; | ||
| 65 | $field .= qq! checked="checked"! if ($self->checked or $self->current_value); | ||
| 66 | $field .= qq! disabled="disabled" readonly="readonly"!; | ||
| 67 | $field .= qq! />\n!; | ||
| 68 | |||
| 69 | Jifty->web->out($field); | ||
| 70 | return ''; | ||
| 71 | } | ||
| 72 | |||
| 73 | =head2 javascript_preempt | ||
| 74 | |||
| 75 | By default, javascript (such as onclick handlers) should not actually | ||
| 76 | prevent browsers from placing the checkmark in the checkbox. | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | sub javascript_preempt { return 0; } | ||
| 81 | |||
| 82 | 1; |