[html-formfu] proper way to set options for radiogroup
Brian Cassidy
brian.cassidy at nald.ca
Mon Sep 24 15:18:14 GMT 2007
Hey All,
If someone could please refresh my memory, I'm attempting to populate a
radiogroup with options from a catalyst model, setting defaults is an
entry is in the stash.
It shows the options okay, but it's not setting the default properly.
I've examined $self->_options to see what comes out and the appropriate
entry has default and value being equal (which i thought was the
condition to make checked="checked" show up) ...
Here is what I have -- i could've /sworn/ it was working earlier.
---
package MyApp::Form::Element::AccountRoles;
use strict;
use warnings;
use base qw( HTML::FormFu::Element::Radiogroup );
sub process {
my $self = shift;
$self->container_tag( 'div' );
$self->attributes( { class => 'radiogroup' } );
$self->name( 'role' );
my $c = $self->form->stash->{ context };
my $roles
= $c->model( 'AccountRole' )->search( {}, { order_by => 'name' } );
my %uroles = eval {
map { $_->id => $_->id } $c->stash->{ account }->roles;
};
$self->options(
[ map {
{ value => $_->id,
default => $uroles{ $_->id } || undef,
label => ucfirst $_->name,
attributes => { id => 'role_' . $_->id, },
label_attributes => { for => 'role_' . $_->id, },
}
} $roles->all
]
);
return $self->next::method( @_ );
}
1;
---
Any ideas?
-Brian
More information about the HTML-FormFu
mailing list