| 1 |
package HTML::FormHandler::Widget::Field::Compound; |
| 2 |
# ABSTRACT: compound field widget |
| 3 |
$HTML::FormHandler::Widget::Field::Compound::VERSION = '0.410002'; |
| 4 |
use Moose::Role; |
| 5 |
|
| 6 |
|
| 7 |
sub render_subfield { |
| 8 |
my ( $self, $result, $subfield ) = @_; |
| 9 |
my $subresult = $result->field( $subfield->name ); |
| 10 |
|
| 11 |
return "" unless $subresult; |
| 12 |
return $subfield->render( $subresult ); |
| 13 |
} |
| 14 |
|
| 15 |
sub render_element { |
| 16 |
my ( $self, $result ) = @_; |
| 17 |
$result ||= $self->result; |
| 18 |
|
| 19 |
my $output = ''; |
| 20 |
foreach my $subfield ( $self->sorted_fields ) { |
| 21 |
$output .= $self->render_subfield( $result, $subfield ); |
| 22 |
} |
| 23 |
$output =~ s/^\n//; # remove newlines so they're not duplicated |
| 24 |
return $output; |
| 25 |
} |
| 26 |
|
| 27 |
sub render { |
| 28 |
my ( $self, $result ) = @_; |
| 29 |
$result ||= $self->result; |
| 30 |
die "No result for form field '" . $self->full_name . "'. Field may be inactive." unless $result; |
| 31 |
my $output = $self->render_element( $result ); |
| 32 |
return $self->wrap_field( $result, $output ); |
| 33 |
} |
| 34 |
|
| 35 |
use namespace::autoclean; |
| 36 |
1; |
| 37 |
|
| 38 |
__END__ |
| 39 |
|
| 40 |
=pod |
| 41 |
|
| 42 |
=encoding UTF-8 |
| 43 |
|
| 44 |
=head1 NAME |
| 45 |
|
| 46 |
HTML::FormHandler::Widget::Field::Compound - compound field widget |
| 47 |
|
| 48 |
=head1 VERSION |
| 49 |
|
| 50 |
version 0.410002 |
| 51 |
|
| 52 |
=head1 SYNOPSIS |
| 53 |
|
| 54 |
Widget for rendering a compound field. |
| 55 |
|
| 56 |
=head1 AUTHOR |
| 57 |
|
| 58 |
FormHandler Contributors - see HTML::FormHandler |
| 59 |
|
| 60 |
=head1 COPYRIGHT AND LICENSE |
| 61 |
|
| 62 |
This software is copyright (c) 2017 by Gerda Shank. |
| 63 |
|
| 64 |
This is free software; you can redistribute it and/or modify it under |
| 65 |
the same terms as the Perl 5 programming language system itself. |
| 66 |
|
| 67 |
=cut |