File Coverage

blib/lib/HTML/FormHandler/Field/RmElement.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition 3 8 37.5
subroutine 4 4 100.0
pod 0 1 0.0
total 27 33 81.8


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Field::RmElement;
2             # ABSTRACT: field to support repeatable javascript remove
3             $HTML::FormHandler::Field::RmElement::VERSION = '0.40068';
4 1     1   808 use HTML::FormHandler::Moose;
  1         3  
  1         12  
5             extends 'HTML::FormHandler::Field::Display';
6 1     1   2914 use HTML::FormHandler::Render::Util ('process_attrs');
  1         3  
  1         11  
7              
8              
9             has '+do_wrapper' => ( default => 1 );
10             has '+value' => ( default => 'Remove' );
11              
12             sub build_render_method {
13             return sub {
14 2     2   5 my ( $self, $result ) = @_;
15 2   33     6 $result ||= $self->result;
16              
17 2   33     65 my $value = $self->html || $self->html_filter($self->_localize($self->value));
18 2         14 my $attrs = $self->element_attributes($result);
19 2         4 push @{$attrs->{class}}, ( 'rm_element', 'btn' );
  2         10  
20 2         52 $attrs->{'data-rep-elem-id'} = $self->parent->id;
21 2         72 $attrs->{id} = $self->id;
22 2         11 my $attr_str = process_attrs($attrs);
23 2   50     13 my $wrapper_tag = $self->get_tag('wrapper_tag') || 'div';
24 2         10 my $output = qq{<$wrapper_tag$attr_str>$value</$wrapper_tag>};
25 2         57 $output = $self->wrap_field($self->result, $output);
26 2         20 return $output;
27 2     2 0 74 };
28             }
29              
30             __PACKAGE__->meta->make_immutable;
31             1;
32              
33             __END__
34              
35             =pod
36              
37             =encoding UTF-8
38              
39             =head1 NAME
40              
41             HTML::FormHandler::Field::RmElement - field to support repeatable javascript remove
42              
43             =head1 VERSION
44              
45             version 0.40068
46              
47             =head1 SYNOPSIS
48              
49             EXAMPLE field for rendering an RmElement field for
50             doing javascript removals of repeatable elements.
51              
52             You probably want to make your own.
53              
54             The main requirements are that the button have 1) the
55             'rm_element' class, 2) a 'data-rep-elem-id' attribute that
56             contains the id of the repeatable instance that you want
57             to remove (C<< $self->parent->id >>).
58              
59             This field should be a subfield of the Repeatable, probably
60             either first or last.
61              
62             =head1 NAME
63              
64             HTML::FormHandler::Field::RmElement
65              
66             =head1 ATTRIBUTES
67              
68             has_field 'rm_element' => ( type => 'RmElement',
69             value => 'Remove',
70             );
71              
72             =head1 AUTHOR
73              
74             FormHandler Contributors - see HTML::FormHandler
75              
76             =head1 COPYRIGHT AND LICENSE
77              
78             This software is copyright (c) 2017 by Gerda Shank.
79              
80             This is free software; you can redistribute it and/or modify it under
81             the same terms as the Perl 5 programming language system itself.
82              
83             =cut