[html-formfu] Subclassing elements and adding config options

Michael Reddick michael.reddick at gmail.com
Mon Apr 20 14:54:28 GMT 2009


On Mon, Apr 20, 2009 at 9:44 AM, Carl Franks <fireartist at gmail.com> wrote:

> 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 =3D $form->element({
>        type =3D> 'UserSelect',
>        name =3D> '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 =3D shift;
>
>    $self->_populate_options
>        if !@{ $self->options };
>
>    $self->next::method( @_ );
> }
>
> _______________________________________________
> HTML-FormFu mailing list
> HTML-FormFu at lists.scsys.co.uk
> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu
>


Awesome, thanks. Should I type this up for a cookbook entry or something?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090420/35=
97577b/attachment-0001.htm


More information about the HTML-FormFu mailing list