| 1 | package HTML::Widget::Element::Hidden; | ||
| 2 | |||
| 3 | use warnings; | ||
| 4 | use strict; | ||
| 5 | use base 'HTML::Widget::Element'; | ||
| 6 | use NEXT; | ||
| 7 | |||
| 8 | __PACKAGE__->mk_accessors(qw/value retain_default/); | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | HTML::Widget::Element::Hidden - Hidden Element | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | my $e = $widget->element( 'Hidden', 'foo' ); | ||
| 17 | $e->value('bar'); | ||
| 18 | |||
| 19 | =head1 DESCRIPTION | ||
| 20 | |||
| 21 | Hidden Element. | ||
| 22 | |||
| 23 | =head1 METHODS | ||
| 24 | |||
| 25 | =head2 value | ||
| 26 | |||
| 27 | Default value is 1. | ||
| 28 | |||
| 29 | =head2 retain_default | ||
| 30 | |||
| 31 | If true, overrides the default behaviour, so that after a field is missing | ||
| 32 | from the form submission, the xml output will contain the default value, | ||
| 33 | rather than be empty. | ||
| 34 | |||
| 35 | =head2 new | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | sub new { | ||
| 40 | shift->NEXT::new(@_)->value(1); | ||
| 41 | } | ||
| 42 | |||
| 43 | =head2 containerize | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | sub containerize { | ||
| 48 | my ( $self, $w, $value, $errors, $args ) = @_; | ||
| 49 | |||
| 50 | $value = ref $value eq 'ARRAY' ? shift @$value : $value; | ||
| 51 | |||
| 52 | $value = $self->value | ||
| 53 | if ( not defined $value ) | ||
| 54 | and $self->retain_default || not $args->{submitted}; | ||
| 55 | |||
| 56 | my $i = $self->mk_input( $w, { type => 'hidden', value => $value } ); | ||
| 57 | |||
| 58 | return $self->container( { element => $i } ); | ||
| 59 | } | ||
| 60 | |||
| 61 | =head1 SEE ALSO | ||
| 62 | |||
| 63 | L<HTML::Widget::Element> | ||
| 64 | |||
| 65 | =head1 AUTHOR | ||
| 66 | |||
| 67 | Sebastian Riedel, C<sri@oook.de> | ||
| 68 | |||
| 69 | =head1 LICENSE | ||
| 70 | |||
| 71 | This library is free software, you can redistribute it and/or modify it under | ||
| 72 | the same terms as Perl itself. | ||
| 73 | |||
| 74 | =cut | ||
| 75 | |||
| 76 | 1; |