Spark::Form::Field - Superclass for all Form Fields
version 0.2102
Field superclass. Must subclass this to be considered a field.
package My::Field; use Moose; require Spark::Form::Field; extends 'Spark::Form::Field'; with 'Spark::Form::Field::Role::Validateable'; with 'Spark::Form::Field::Role::Printable::XHTML'; sub _validate { my $self = shift; #validate existence of data if ($self->value) { #If we're valid, we should say so $self->valid(1); } else { #error will call $self->valid(0) and also set an error. $self->error('no value') } #And we should return boolean validity $self->valid } sub to_xhtml { #Rather poorly construct an XHTML tag '<input type="checkbox" value="' . shift-value . '">'; }
Note that you might want to look into HTML::Tiny. Or better still, SparkX::Form::Field::Plugin::StarML.
There are a bunch of pre-built fields you can actually use in SparkX::Form::BasicFields.
Name of the field in the data source. Will be slurped on demand. Required at validation time, not at construction time.
Reference to the form it is a member of.
Value in the field.
Treat as read-only. Whether the field is valid.
Treat as read-only. The list of errors generated in validation.
Returns the label if present, else the field name.
Returns true always. Subclass and fill in _validate to do proper validation. See the synopsis.
_validate
Adds an error to the current field's list.
James Laver L<http://jameslaver.com>
This software is copyright (c) 2009 by James Laver <sprintf qw(%s@%s.%s cpan jameslaver com)>.
<sprintf qw(%s@%s.%s cpan jameslaver com)>
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Spark::Form, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Spark::Form
CPAN shell
perl -MCPAN -e shell install Spark::Form
For more information on module installation, please visit the detailed CPAN module installation guide.