Thank you for these hints. But inn my customized element, I used multi instead of checkbox, below is my code:

use strict;
use warnings;

use base qw( HTML::FormFu::Element::multi );

__PACKAGE__->mk_accessors(qw( group_type ));

sub render {
 my $self = shift;
 my $type = $self->group_type;

 $self->attributes( { class => $type . 'group' } );
 my $c = $self->form->stash->{ context };
 my $roles = $c->model( 'Links::AccountRole' )->search;
 $self->elements( [ map {
{ type => $type, name=>'role', value=> $_->id, label => $_->name, id=>'role_'.$_->id, /*'checked'(maybe a condition here)*/ }
 } $roles->all ] );

  return $self->SUPER::render( @_ );
}

1;

In my app, I have a 'update' which I can get the details of each user in database. Each user has a checkbox to indicate whether he is administrator. If he is, the checkbox will be checked, otherwise the checkbox is unchecked. Right now every checkbox is checked, even the user is not an administrator. That's the part I am struggling with.

Kewei

_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to