[html-formfu] custom element with automatic constraint
Carl Franks
fireartist at gmail.com
Tue Feb 26 06:48:11 GMT 2008
On 26/02/2008, Steve Caldwell <info-formfu at caldwellhb.com> wrote:
> All,
>
> Because I have so many instances of this in my code:
>
> - type: Select
> ...
> constraints:
> - type: AutoSet
>
>
> I wanted to create a custom class that inherits from Element::Select and
> automatically includes AutoSet as a constraint. After poking around at
> the documentation/code for a little bit, it's not immediately obvious to
> me how to do this. Has anyone tried this before, or have any advice on
> where I could look?
I believe this should work (untested):
package MySelect;
use strict;
use base 'HTML::FormFu::Element::Select';
use Class::C3;
sub process {
my $self = shift;
$self->constraint('AutoSet')
unless $self->get_constraint({ type => 'AutoSet' });
return $self->next::method(@_);
}
---
element:
- type: '+MySelect'
The '+' prefix is because it isn't within the HTML::FormFu::Element::*
namespace.
Carl
More information about the HTML-FormFu
mailing list