I'm using HTML::FormHandler, and as to not repeat code I'd like to take advantage of its subclassing features. Currently I have two forms:
myapp::Form::Account::Base
myapp::Form::Account::Register
myapp::Form::Account::Register
inherits from myapp::Form::Account::Base
. myapp::Form::Account::Base
Has an email field, that is defined like this:
has_field 'email' => (
label => 'Email',
type => 'Text',
apply => [ Email ],
element_class => [qw/email/],
required => 1,
unique => 1,
element_attr => {autocomplete=>"off"}, #for register page
);
In myapp::Form::Account::Register
, I'd like to have the exact same defined email field, but I would like to add the class "uniqueemail" to it. However, whenever I do this:
has_field 'email' => (
element_class => [qw/uniqueemail/],
);
in myapp::Form::Account::Register
, It just completely overwrites the parent form's definition of the email field, and makes a new one. Is there anyway to just subclass the parent's form field or add to it, or do I just have to redefine the email field again in order to get the changes I want? Thanks!
You can provide a field definition that overrides the parent definition by using a '+' before the field name:
has_field '+email' => (
element_class => [qw/uniqueemail/],
);