Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Jan 21, 2012
1 parent 2bd2398 commit 68b6260
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
5 changes: 1 addition & 4 deletions lib/HTML/FormHandler/Field.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1214,16 +1214,13 @@ sub BUILD {
$self->_set_default( $self->_comp_default_meth )
if( $self->form && $self->form->can( $self->_comp_default_meth ) );
$self->add_widget_name_space( $self->form->widget_name_space ) if $self->form;
# widgets will already have been applied by BuildFields, but this allows
# testing individual fields
# $self->apply_rendering_widgets unless ($self->can('render') );
$self->add_action( $self->trim ) if $self->trim;
$self->_build_apply_list;
$self->add_action( @{ $params->{apply} } ) if $params->{apply};
}

# this is the recursive routine that is used
# to initial fields if there is no initial object and no params
# to initialize field results if there is no initial object and no params
sub _result_from_fields {
my ( $self, $result ) = @_;

Expand Down
5 changes: 3 additions & 2 deletions lib/HTML/FormHandler/Foo.pm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package HTML::FormHandler::Foo;
# ABSTRACT: Experiment in loading form from config file
use Moose;
extends 'HTML::FormHandler';
with 'HTML::FormHandler::Render::WithTT';
Expand All @@ -13,8 +14,8 @@ use 5.010;
#);

has 'form_error_message' => ( isa => 'Str', is => 'rw' );
has 'javascript_src' => ( is => 'Str', is => 'rw' );
has 'javascript' => ( is => 'STr', is => 'rw' );
has 'javascript_src' => ( isa => 'Str', is => 'rw' );
has 'javascript' => ( isa => 'Str', is => 'rw' );

sub before_build {
my $self = shift;
Expand Down
4 changes: 4 additions & 0 deletions lib/HTML/FormHandler/Manual.pod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ IRC:

Join #formhandler on irc.perl.org

Mailing list:

http://groups.google.com/group/formhandler

=head1 AUTHOR

gshank: Gerda Shank <gshank@cpan.org>
Expand Down
31 changes: 20 additions & 11 deletions lib/HTML/FormHandler/Manual/Templates.pod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,19 @@ Documentation on templates to use with L<HTML::FormHandler>

=head1 Using templates

There are lots of different ways to set up templates. One way is to
create a 'widget' directory, and store template snippets there.
There is a FormHandler Template Toolkit rendering role at
L<HTML::FormHandler::Render::WithTT>, with a testcase in t/render_withtt.t.
Normally, however, it probably won't make much sense to use both a
TT parser in FormHandler, and a separate one for the "complete" templates,
so it seems like the TT renderer would mainly be useful for tests,
or as an example of how to do TT rendering with HFH.

There are lots of different ways to set up templates. There are sample
templates installed in FormHandler's 'share' directory. These templates
are now organized more-or-less similarly to the widget roles, with 'field',
'wrapper', and 'form' directories, but many other organizations are possible.

Another organization would be to store all template snippets in a 'widget' directory.

You can use the default 'widget' for the field class, or set the 'widget'
for the field in your form:
Expand All @@ -34,23 +45,21 @@ And include them in a generic template:

[% PROCESS widget/form_end.tt %]

In release 0.36000, the templates were rearranged to match the widgets better,
so that there are field, form, and wrapper directories. (See the templates in the
share directory.)

=head1 Field attributes

There is a 'process_attrs' method in the HTML::FormHandler::Render::Util which
can be used to handle attributes in fields, wrappers, and labels:
If you want to use the 'process_attrs' function to pull in HTML attributes
for the input elements, wrappers, and labels, you would need to pass that
function into your TT setup. See L<HTML::FormHandler::Render::WithTT> for an
example:

use HTML::FormHandler::Render::Util ('process_attrs');
$c->stash( process_attrs => &process_attrs ); # or add to TT vars in your view

label [% process_attrs(f.label_attributes) %]for="[% f.html_name %]">
[% f.label %]: </label>
<input type="[% f.input_type %]" name="[% f.html_name %]" id="[% f.id %]"
[% process_attrs(f.attributes) %] value="[% f.fif %]">

The 'process_attrs' method can be added to your own TT view in a similar way to
L<HTML::FormHandler::Render::WithTT>, where it's added to the TT vars.

=head1 Sample templates

Note that the following templates assume that the field is in a TT variable "f",
Expand Down
3 changes: 2 additions & 1 deletion t/config.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use Test::More;
use HTML::FormHandler::Foo;
use FindBin;

# test Foo class for loading form info from config

my $expected =
'<form action="/login" id="login_form" method="post">
<div class="text label">
Expand All @@ -25,7 +27,6 @@ my $expected =
</form>
';


my $form = HTML::FormHandler::Foo->new( config_file => "$FindBin::Bin/var/form1.yml" );
$form->process({});
is( $form->num_fields, 4, 'right number of fields');
Expand Down

0 comments on commit 68b6260

Please sign in to comment.