[html-formfu] proper way to set options for radiogroup

Brian Cassidy brian.cassidy at nald.ca
Mon Sep 24 15:38:48 GMT 2007


Carl Franks wrote:
> No, 'default' would be ignored (lost) during options().
> Only 1 radio item's value can match the default.
> It should be:
> 
>     $self->options(
>         [   map {
>                 {   value            => $_->id,
>                     label            => ucfirst $_->name,
>                     attributes       => { id => 'role_' . $_->id, },
>                     label_attributes => { for => 'role_' . $_->id, },
>                 }
>                 } $roles->all
>         ]
>     );
> 
>     $self->default( $default );

Boy, is my face red.

Some of that code was held-over from when a user could have multiple 
roles -- that is no longer the case. The following worked as desired:

     $self->default( eval { $c->stash->{ account }->roles->first->id } );

Muchos gracias, Carl.

-Brian





More information about the HTML-FormFu mailing list