[html-formfu] Subclassing elements and adding config options
Carl Franks
fireartist at gmail.com
Mon Apr 20 14:44:18 GMT 2009
2009/4/20 Michael Reddick <michael.reddick at gmail.com>:
> I'm trying to subclass the Select element and be able to change which
> options are added via a variable (user_type) in the form config. The
> variable (user_type) isn't being initialized when _populate_options is
> called. How should I be doing this? Here is the code:
How are you setting 'user_type' ?
If it's in a config file, such as:
- type: UserSelect
name: foo
user_type: bar
then internally, HTML-FormFu is essentially doing:
my $elem = $form->element({
type => 'UserSelect',
name => 'foo',
});
$elem->user_type('bar');
which is why 'user_type' isn't yet set in _populate_options(), when
it's called by new().
I'd probably do it during process() instead:
sub process {
my $self = shift;
$self->_populate_options
if !@{ $self->options };
$self->next::method( @_ );
}
More information about the HTML-FormFu
mailing list