<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package HTML::FormHandler::Widget::Wrapper::Simple;
# ABSTRACT: simple field wrapper
$HTML::FormHandler::Widget::Wrapper::Simple::VERSION = '0.40068';
use Moose::Role;
use namespace::autoclean;
use HTML::FormHandler::Render::Util ('process_attrs');

with 'HTML::FormHandler::Widget::Wrapper::Base';



sub wrap_field {
    my ( $self, $result, $rendered_widget ) = @_;

    my $output;
    # get wrapper tag if set
    my $label_tag = $self-&gt;label_tag || '';
    my $wrapper_tag;
    if( $self-&gt;do_wrapper ) {
        $output .= $self-&gt;get_tag('before_wrapper');
        $wrapper_tag = $self-&gt;get_tag('wrapper_tag');
        # default wrapper tags
        $wrapper_tag ||= $self-&gt;has_flag('is_repeatable') ? 'fieldset' : 'div';
        # get attribute string
        my $attrs = process_attrs( $self-&gt;wrapper_attributes($result) );
        # write wrapper tag
        $output .= qq{\n&lt;$wrapper_tag$attrs&gt;};
        $label_tag = 'legend' if $wrapper_tag eq 'fieldset';
    }
    # write label; special processing for checkboxes
    $rendered_widget = $self-&gt;wrap_checkbox($result, $rendered_widget)
        if ( lc $self-&gt;widget eq 'checkbox' );
    $output .= "\n" . $self-&gt;do_render_label($result, $label_tag)
        if $self-&gt;do_label;
    # append 'before_element'
    $output .= $self-&gt;get_tag('before_element');

    # start controls div
    if ( $self-&gt;get_tag('controls_div') ) {
        $output .= qq{\n&lt;div class="controls"&gt;};
    }
    elsif ( $self-&gt;has_element_wrapper_class ) {
        my $ew_attr = $self-&gt;element_wrapper_attributes($result);
        my $element_wrapper_attrs =  process_attrs( $ew_attr );
        $output .= qq{\n&lt;div$element_wrapper_attrs&gt;};
    }

    # the input element itself
    $output .= "\n$rendered_widget";

    # close controls div
    if ( $self-&gt;get_tag('controls_div') || $self-&gt;has_element_wrapper_class ) {
        # end control div
        $output .= "\n&lt;/div&gt;";
    }

    # the 'after_element'
    $output .= $self-&gt;get_tag('after_element');
    # the error messages
    unless( $self-&gt;get_tag('no_errors') ) {
        my $error_class = $self-&gt;get_tag('error_class') || 'error_message';
        $output .= qq{\n&lt;span class="$error_class"&gt;$_&lt;/span&gt;}
            for $result-&gt;all_errors;
        # warnings (incompletely implemented - only on field itself)
        my $warning_class = $self-&gt;get_tag('warning_class') || 'warning_message';
        $output .= qq{\n&lt;span class="warning_message"&gt;$_&lt;/span&gt;}
            for $result-&gt;all_warnings;
    }
    if( $self-&gt;do_wrapper ) {
        $output .= "\n&lt;/$wrapper_tag&gt;";
        $output .= $self-&gt;get_tag('after_wrapper');
    }
    return "$output";
}


1;

__END__

=pod

=encoding UTF-8

=head1 NAME

HTML::FormHandler::Widget::Wrapper::Simple - simple field wrapper

=head1 VERSION

version 0.40068

=head1 SYNOPSIS

This is the default wrapper role. It will be installed if
no other wrapper is specified and widget_wrapper is not set to
'none'.

Relevant field flags:

   do_wrapper
   do_label

If 'do_label' is set and not 'do_wrapper', only the label plus
the form element will be rendered.

Supported 'tags', all set via the 'tags' hashref on the field:

    wrapper_tag    -- the tag to use in the wrapper, default 'div'

    label_tag      -- tag to use for label (default 'label')
    label_after    -- string to append to label, for example ': ' to append a colon

    before_element -- string that goes right before the element
    after_element  -- string that goes right after the element

    no_errors      -- don't issue error messages on the field
    error_class    -- class for error messages (default 'error_message')
    warning_class  -- class for warning messages (default 'warning_message' )

    no_wrapped_label -- for checkboxes. Don't provide an inner wrapped label
                        (from Base wrapper)

Example:

    has_field 'foo' =&gt; ( tags =&gt; { wrapper_tag =&gt; 'span', no_errors =&gt; 1 } );

=head1 AUTHOR

FormHandler Contributors - see HTML::FormHandler

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Gerda Shank.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
</pre></body></html>