| 1 |
package HTML::FormHandler::Field::RmElement; |
| 2 |
# ABSTRACT: field to support repeatable javascript remove |
| 3 |
$HTML::FormHandler::Field::RmElement::VERSION = '0.410002'; |
| 4 |
use HTML::FormHandler::Moose; |
| 5 |
extends 'HTML::FormHandler::Field::Display'; |
| 6 |
use HTML::FormHandler::Render::Util ('process_attrs'); |
| 7 |
|
| 8 |
|
| 9 |
has '+do_wrapper' => ( default => 1 ); |
| 10 |
has '+value' => ( default => 'Remove' ); |
| 11 |
|
| 12 |
sub build_render_method { |
| 13 |
return sub { |
| 14 |
my ( $self, $result ) = @_; |
| 15 |
$result ||= $self->result; |
| 16 |
|
| 17 |
my $value = $self->html || $self->html_filter($self->_localize($self->value)); |
| 18 |
my $attrs = $self->element_attributes($result); |
| 19 |
push @{$attrs->{class}}, ( 'rm_element', 'btn' ); |
| 20 |
$attrs->{'data-rep-elem-id'} = $self->parent->id; |
| 21 |
$attrs->{id} = $self->id; |
| 22 |
my $attr_str = process_attrs($attrs); |
| 23 |
my $wrapper_tag = $self->get_tag('wrapper_tag') || 'div'; |
| 24 |
my $output = qq{<$wrapper_tag$attr_str>$value</$wrapper_tag>}; |
| 25 |
$output = $self->wrap_field($self->result, $output); |
| 26 |
return $output; |
| 27 |
}; |
| 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.410002 |
| 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 |