[html-formfu] Subclassing elements and adding config options
Michael Reddick
michael.reddick at gmail.com
Mon Apr 20 14:36:18 GMT 2009
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:
package Tsunami::HTML::FormFu::Element::UserSelect;
use base 'HTML::FormFu::Element::Select';
use Class::C3;
use SessionInfo;
__PACKAGE__->mk_item_accessors( qw( user_type ) );
sub new {
my $self =3D shift->next::method(@_);
$self->_populate_options;
return $self;
}
sub _populate_options {
my $self =3D shift;
my $schema =3D $SessionInfo->schema;
warn $self->user_type;
my @users =3D
$schema->resultset('User')->active_users
->search(undef, { 'order_by' =3D> 'me.lastname asc' });
$self->options( [
{ value =3D> '', label =3D> 'All' },
map { { value =3D> $_->userid, label =3D> $_->lastname . ', ' .
$_->firstname } }
@users
] );
}
1;
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090420/7f=
1e2fe4/attachment.htm
More information about the HTML-FormFu
mailing list