NAME

Form::Toolkit::Form - A Moose base class for Form implementation

BUILD

Hooks in the Moose BUILD to call build_fields

fast_clone

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();

id

Shortcut to $this->meta->id();

do_accept

Accepts a form visitor returns this visitor's visit_form method returned value.

Usage:

my $result = $this->do_accept($visitor);

build_fields

Called after Form creation to add_field to $self.

This should be the method you need to implement in your subclasses.

Usage:

sub build_fields{
  my ($self) = @_;
  $self->add_field('Date' , 'a_date_field');
  $self->add_field('String' , 'a string field');
  # etc..
}

add_error

Adds an error to this form (as a string).

$this->add_error('Something is globally wrong');

add_field

Usage:

$this->add_field('field_name');
$this->add_field('FieldType', 'field_name'); ## 'FieldType' is turned into Form::Toolkit::Field::FieldType'.
$this->add_field($field_instance);

field

Get a field by name or undef.

Usage:

my $field = $this->field('my_field');

is_valid

Opposite of has_errors.

has_errors

Returns true if this form has errors, false otherwise.

Usage:

if( $this->has_errors() ){
  ...
}

dump_errors

Convenience debugging method.

Returns

{ _form => [ 'error1' , ... ],
  field1 => [ 'error' , ... ],
  field2 => [ 'error' , ... ],
  ...
}

reset

Alias for clear. please override clear if you want. Don't touch this.

clear

Resets this form to its void state. After the call, this form is ready to be used again.

values_hash

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.

literal

Returns a litteral representation of this form (as a Base64 encoded JSON byte string).

Usage:

print $this->litteral();

from_literal

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.

Usage:

my $form = $this->from_literal($litteral);

fill_hash

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.

Usage:

$this->fill_hash({ field1 => 'value' , field2 => undef , field3 => [ 'a' , 'b' , 'c' ]});

$this->fill_hash($another_form->values_hash());

if( $this->has_errors() ){

}