| 1 |
package HTML::FormHandler::Widget::Field::Repeatable; |
| 2 |
# ABSTRACT: repeatable field widget |
| 3 |
$HTML::FormHandler::Widget::Field::Repeatable::VERSION = '0.410002'; |
| 4 |
use Moose::Role; |
| 5 |
with 'HTML::FormHandler::Widget::Field::Compound'; |
| 6 |
|
| 7 |
|
| 8 |
has 'wrap_repeatable_element_method' => ( |
| 9 |
traits => ['Code'], |
| 10 |
is => 'ro', |
| 11 |
isa => 'CodeRef', |
| 12 |
handles => { 'wrap_repeatable_element' => 'execute_method' }, |
| 13 |
); |
| 14 |
|
| 15 |
sub render_subfield { |
| 16 |
my ( $self, $result, $subfield ) = @_; |
| 17 |
|
| 18 |
my $subresult = $result->field( $subfield->name ); |
| 19 |
|
| 20 |
return "" unless $subresult |
| 21 |
or ( $self->has_flag( "is_repeatable") |
| 22 |
and $subfield->name < $self->num_when_empty |
| 23 |
); |
| 24 |
|
| 25 |
my $output = $subfield->render($subresult); |
| 26 |
if ( $self->wrap_repeatable_element_method ) { |
| 27 |
$output = $self->wrap_repeatable_element($output, $subfield->name); |
| 28 |
} |
| 29 |
return $output; |
| 30 |
} |
| 31 |
|
| 32 |
use namespace::autoclean; |
| 33 |
1; |
| 34 |
|
| 35 |
__END__ |
| 36 |
|
| 37 |
=pod |
| 38 |
|
| 39 |
=encoding UTF-8 |
| 40 |
|
| 41 |
=head1 NAME |
| 42 |
|
| 43 |
HTML::FormHandler::Widget::Field::Repeatable - repeatable field widget |
| 44 |
|
| 45 |
=head1 VERSION |
| 46 |
|
| 47 |
version 0.410002 |
| 48 |
|
| 49 |
=head1 SYNOPSIS |
| 50 |
|
| 51 |
Renders a repeatable field |
| 52 |
|
| 53 |
=head1 AUTHOR |
| 54 |
|
| 55 |
FormHandler Contributors - see HTML::FormHandler |
| 56 |
|
| 57 |
=head1 COPYRIGHT AND LICENSE |
| 58 |
|
| 59 |
This software is copyright (c) 2017 by Gerda Shank. |
| 60 |
|
| 61 |
This is free software; you can redistribute it and/or modify it under |
| 62 |
the same terms as the Perl 5 programming language system itself. |
| 63 |
|
| 64 |
=cut |