| Form-Sensible documentation | Contained in the Form-Sensible distribution. |
Form::Sensible::Field::SubForm - encapsulate an entire form within another.
use Form::Sensible::Field::SubForm;
my $object = Form::Sensible::Field::SubForm->new( form => $otherform );
$object->do_stuff();
The subform field type allows you to embed one form within another. The fields in the subform are submitted and validated as though they belong to the primary form, meaning the fieldnames are used 'as is.' Please note that this feature is experimental at best and how it is used is still subject to change.
formThe sub-form to include into this field.
Jay Kuri - <jayk@cpan.org>
Ionzero LLC. http://ionzero.com/
Copyright 2009 by Jay Kuri <jayk@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Form-Sensible documentation | Contained in the Form-Sensible distribution. |
package Form::Sensible::Field::SubForm; use Moose; use namespace::autoclean; extends 'Form::Sensible::Field'; has 'form' => ( is => 'rw', isa => 'Form::Sensible::Form', required => 1, ); sub BUILDARGS { my $class = shift; my $args = $_[0]; if (!ref($args)) { $args = { @_ }; } ## could probably do this with some sort of coersion - not sure if I want to though. if (ref($args->{'form'}) eq 'HASH') { $args->{'form'} = Form::Sensible->create_form($args->{'form'}); } return $class->SUPER::BUILDARGS($args); } sub BUILD { my $self = shift; if (!exists($self->form->render_hints->{'form_template_prefix'})) { $self->form->render_hints->{'form_template_prefix'} = 'subform'; } } around 'value_delegate' => sub { my $orig = shift; my $self = shift; return $self->$orig() unless @_; my $delegate = shift; foreach my $field ($self->form->get_fields()) { $field->value_delegate( $delegate ); } return $self->$orig($delegate); }; sub get_additional_configuration { my ($self, $template_only) = @_; return { 'form' => $self->form->flatten($template_only), }; } around 'validate' => sub { my $orig = shift; my $self = shift; return ($self->form->validate(), $self->$orig(@_)); }; __PACKAGE__->meta->make_immutable; 1; __END__