[html-formfu] Populating options for Select elements
Carl Franks
fireartist at gmail.com
Tue Jun 2 07:28:56 GMT 2009
2009/6/1 Nigel Metheringham <nigel.metheringham at dev.intechnology.co.uk>:
>
> On 1 Jun 2009, at 13:36, Carl Franks wrote:
>
>> I achieve this by creating a custom plugin which inherits from
>> HTML::FormFu::Plugin and defines a 'pre_process' method that does the
>> heavy-work.
>
> Any chance you have some sample code showing this sort of usage?
This is an example from my current project.
$contenxt->stash->{group} is populated by a Chained action.
This is added to the Select element, so $self->parent refers to the
Select element.
type: Select
name: foo
plugins:
- CAMS::SelectPanel
package HTML::FormFu::Plugin::CAMS::SelectPanel;
use strict;
use base 'HTML::FormFu::Plugin';
sub pre_process {
my ($self) = @_;
my $context = $self->form->stash->{context};
my $group = $context->stash->{group};
my $panels = $group->search_related(
'group_panel_rel',
{},
{
order_by => ['order_id'],
},
);
my @options;
for my $panel ( $panels->all ) {
push @options, [ $panel->id, $panel->name ];
}
$self->parent->options( \@options );
return;
}
1;
More information about the HTML-FormFu
mailing list