Form::Toolkit::Form - A Moose base class for Form implementation
Hooks in the Moose BUILD to call build_fields
Returns fast clone of this form. This is field value focused and as shallow as possible, so use with care if you want to change anything else than field values in your clones.
Benchmarking has shown this is 50x faster than the MooseX::Clone based clone method.
Usage:
my $clone = $this->fast_clone();
Shortcut to $this->meta->id();
Accepts a form visitor returns this visitor's visit_form method returned value.
my $result = $this->do_accept($visitor);
Called after Form creation to add_field to $self.
This should be the method you need to implement in your subclasses.
sub build_fields{ my ($self) = @_; $self->add_field('Date' , 'a_date_field'); $self->add_field('String' , 'a string field'); # etc.. }
Adds an error to this form (as a string).
$this->add_error('Something is globally wrong');
$this->add_field('field_name'); $this->add_field('FieldType', 'field_name'); ## 'FieldType' is turned into Form::Toolkit::Field::FieldType'. $this->add_field($field_instance);
Get a field by name or undef.
my $field = $this->field('my_field');
Opposite of has_errors.
Returns true if this form has errors, false otherwise.
if( $this->has_errors() ){ ... }
Convenience debugging method.
Returns
{ _form => [ 'error1' , ... ], field1 => [ 'error' , ... ], field2 => [ 'error' , ... ], ... }
Alias for clear. please override clear if you want. Don't touch this.
Resets this form to its void state. After the call, this form is ready to be used again.
Returns a hash of values like that:
{ a => 'aaa', b => 'bbb', multiplea => [ v1 , v2 , v3 ], multipleb => [] }
You can feed this hash to the Form::Toolkit::Clerk::Hash got populate a similar form.
Returns a litteral representation of this form (as a Base64 encoded JSON byte string).
print $this->litteral();
Class or instance method. Builds a new instance of form from the given litteral (See litteral).
If you are using Forms as other Form's field values, and if all your forms require extra attribute, you can override that IN YOUR CONTAINER form. It will be called as an instance method by the form filling Clerks. See example in test 11.
my $form = $this->from_literal($litteral);
Shortcut to fill this form with a pure Perl hash. After calling this, the form will be validated and populated with error messages if necessary.
$this->fill_hash({ field1 => 'value' , field2 => undef , field3 => [ 'a' , 'b' , 'c' ]}); $this->fill_hash($another_form->values_hash()); if( $this->has_errors() ){ }
To install Form::Toolkit, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Form::Toolkit
CPAN shell
perl -MCPAN -e shell install Form::Toolkit
For more information on module installation, please visit the detailed CPAN module installation guide.