Built-in rendering

14 views
Skip to first unread message

Steve

unread,
Jun 20, 2012, 12:58:16 PM6/20/12
to formh...@googlegroups.com
Hi all,

I'm a bit puzzled by the behavior of the default rendering -
specifically when using 'element_attr'. Consider the following:

has_field 'myInteger' => ( type => 'Integer', element_attr => {'size' =>
'2'} );

Assuming I have the syntax right, why would this directive not be
detected/used with default rendering via [% form.render %]?

Thanks,
Steve

Gerda Shank

unread,
Jun 20, 2012, 3:40:12 PM6/20/12
to formh...@googlegroups.com
Steve:

It works for me.

The following testcase:

================
use strict;
use warnings;
use Test::More;
{

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

has '+name' => ( default => 'test_form' );

has_field 'foo' => ( type => 'Integer', element_attr => { size =>
'2' } );
has_field 'bar' => ( required => 1 );;
}
my $form = MyApp::Form::Test->new;
ok( $form );
$form->process( params => {} );
my $rendered = $form->render;
diag($rendered);

done_testing;
=================

Produces the following HTML:

=================
# <form id="test_form" method="post">
# <div class="form_messages">
# </div>
# <div>
# <label for="foo">Foo</label>
# <input type="text" name="foo" id="foo" size="8" value="" size="2" />
# </div>
# <div>
# <label for="bar">Bar</label>
# <input type="text" name="bar" id="bar" value="" />
# </div>
# </form>
===================

If you're getting something else, please create a testcase to
demonstrate the problem.

Gerda

Steve

unread,
Jun 20, 2012, 4:35:21 PM6/20/12
to formh...@googlegroups.com
Hi Gerda,

The test case worked for me also, however when I add an 'apply' and 'required', things get interesting.  See below for modified field def and result of test.

Field def:

    has_field 'foo' => ( type => 'Integer',
                        apply => [ { check => qr/\d\d\d\d/,
                                   message => 'Please enter a 4-digit value for year' }],

                 element_attr => { size => '2' } );


Result:

# <form id="test_form" method="post">
# <div class="form_messages">
# </div>
# <div>
# <label for="foo">Foo</label>
# <input type="text" name="foo" id="foo" size="8" value="" size="2" />
# </div>
# <div>
# <label for="bar">Bar</label>
# <input type="text" name="bar" id="bar" value="" />
# </div>
# </form>

Gerda Shank

unread,
Jun 20, 2012, 5:35:53 PM6/20/12
to formh...@googlegroups.com
The Integer field is a subclass of Text, which has an explicit 'size' attribute, so you'd normally use that.
    has_field 'foo' => ( type => 'Integer', size => 2 );
Outside of that, I'm not sure what you're referring to - that output looks the same to me. A bit more documentation on which attributes are set explicitly might be good...

Gerda
--
You received this message because you are subscribed to the Google Groups "formhandler" group.
To post to this group, send email to formh...@googlegroups.com.
To unsubscribe from this group, send email to formhandler...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/formhandler?hl=en.

Steve

unread,
Jun 21, 2012, 8:05:26 AM6/21/12
to formh...@googlegroups.com
Thanks Gerda - I changed the field to type 'Text' and now get my expected results.  I agree that a little documentation on 'element_attr' would be beneficial, however it seems to me that any attributes that set expicitly in one's form class should override the default behavior.  Having said that, it is also logical that if you specifically use 'Integer' you've done so for a reason - mainly that you want the field to behave a particular way.  At any rate, thanks again for your help.

Steve

Reply all
Reply to author
Forward
0 new messages