How to add field descriptions? (or how to wrap a widget_tags)

Skip to first unread message

Ask Bjørn Hansen

May 2, 2012, 7:19:22 AM5/2/12
Another Table -> Bootstrap question:

The new (?) "widget_tags" stuff is great in avoiding having to duplicate all of wrap_field to add some extra data around the field.

I'm just mechanically changing my old 'comment' value to 'widget_tags => { after_element => "foo" }', but really what I want the element to be is '<span class="field_info"> {{ after_element }} </span>' or some such. Is there an idiomatic way to do that without having to spell it out?

I experimented a bit with build_update_subfields, but that seems to make defaults. Is that right?


Gerda Shank

May 2, 2012, 9:03:29 AM5/2/12
There are a couple of ways you could do this. One would be to make your
own version of the wrapper, and add rendering of a comment tag.

You could also make 'after_element' a sub or a block:

package MyApp::Form::Test;
use HTML::FormHandler::Moose;
extends 'HTML::FormHandler';

has '+name' => ( default => 'test_form' );
has_block 'comment' => ( tag => 'span', content => 'This is a
comment from a block',
class => ['field_info' ] );
has_field 'foo' => ( tags => { after_element => '%comment' } );
has_field 'bar' => ( tags => { after_element => \&element_comment,
comment => 'my comment' } );

sub element_comment {
my $self = shift;
my $comment = $self->get_tag('comment');
return qq{<span class="field_info">$comment</span>};

Since you probably wouldn't want to create a block for every comment,
you'd probably want a custom block that pulls the comment from a tag (or
somewhere else). Making the 'after_element' tag a sub still means that
you need to set two tags. You can hide some of that by setting all of
your fields to have an 'after_element' sub with
'build_update_subfields', but I imagine you wouldn't want it for some

So there are a lot of options, but I think I'd go with a custom
Bootstrap wrapper, if it were me. It's probably a good idea in any case,
because there's always the risk of future changes if you're using the
stock wrapper.


Reply all
Reply to author
0 new messages