/lib/HTML/FormHandler/Widget/Wrapper/Table.pm

http://github.com/gshank/html-formhandler · Perl · 32 lines · 26 code · 5 blank · 1 comment · 7 complexity · a977fd99ceaae5dcbb9ce7f8e1a9034a MD5 · raw file

  1. package HTML::FormHandler::Widget::Wrapper::Table;
  2. # ABSTRACT: wrapper class for table layout
  3. use Moose::Role;
  4. with 'HTML::FormHandler::Widget::Wrapper::Base';
  5. use HTML::FormHandler::Render::Util ('process_attrs');
  6. sub wrap_field {
  7. my ( $self, $result, $rendered_widget ) = @_;
  8. return $rendered_widget if ( $self->has_flag('is_compound') && $self->get_tag('no_compound_wrapper') );
  9. my $output = "\n<tr" . process_attrs($self->wrapper_attributes($result)) . ">";
  10. if ( $self->has_flag('is_compound') ) {
  11. $output .= '<td>' . $self->do_render_label($result) . '</td></tr>';
  12. }
  13. elsif ( $self->do_label && length( $self->label ) > 0 ) {
  14. $output .= '<td>' . $self->do_render_label($result) . '</td>';
  15. }
  16. if ( !$self->has_flag('is_compound') ) {
  17. $output .= '<td>';
  18. }
  19. $output .= $rendered_widget;
  20. $output .= qq{\n<span class="error_message">$_</span>} for $result->all_errors;
  21. if ( !$self->has_flag('is_compound') ) {
  22. $output .= "</td></tr>\n";
  23. }
  24. return $output;
  25. }
  26. use namespace::autoclean;
  27. 1;