[Html-widget] Status of HTML::Widget?

Carl Franks fireartist at gmail.com
Mon Feb 12 09:35:04 GMT 2007


On 09/02/07, Dave Morriss <m.paradoxa at gmail.com> wrote:
> On 2/9/07, Carl Franks <fireartist at gmail.com> wrote:
> > Yes, HTML::Widget seems to be in limbo at the moment.
> >
> > I've just made public my intended replacement, called HTML::FormFu.
>
> Carl,
>
> Thanks for the clarification. I'll wait and watch developments for a while.
>
> > > I'm quite new to the intricacies of building such applications, and am
> > > a bit thrown by some aspects of H::W.
> >
> > Could you expand on that any further, and I'll see it it's anything
> > I've already dealt with?
>
> My problem is with constraints. My application is heavily derived from
> the Catalyst tutorial code and I have a form I'm using to edit user
> and role details. I populate this with data from the database, except
> for the encrypted password. I want to accept non-password changes
> and/or a new password.
>
> I have no constraints or filters, yet the form fails to validate
> unless I provide a new password. It's as if there's a "phantom" 'All'
> constraint there which I can't remove.
>
> What's happening?
>
> ---- Start Code----
> sub make_edit_widget {
>     my ($self, $c, $user, $roles) = @_;
>
>     # Create an HTML::Widget to build the form
>     my $w = $c->widget('user_form')->method('post');
>
>     # Use custom class to render each element in the form
>     $w->element_container_class('FormElementContainer');
>
>     # Get all known roles from the database
>     my @roleObjs = $c->model("CalendarDB::Roles")->all();
>     my @roles = map {$_->id => $_->role} sort {$a->id cmp $b->id} @roleObjs;
>
>     # Get the team list from the database
>     my @teamObjs = $c->model("CalendarDB::Teams")->all();
>     my @teams = map {$_->id => $_->name} sort {$a->name cmp $b->name} @teamObjs;
>
>     # Extract the user's roles
>     my @role_ids;
>     while (my $role = $roles->next) {
>         push(@role_ids,$role->role_id->id);
>     }
>
>     # Create the form fields. We show the username but don't accept any edits.
>     $w->element('Textfield','first_name')->label('First
> Name')->size(40)->value($user->first_name);
>     $w->element('Textfield','last_name')->label('Last
> Name')->size(40)->value($user->last_name);
>     $w->element('Textfield','username')->label('Username')->size(10)->value($user->username)->
>         attributes({readonly=>'readonly'});
>     $w->element('Textfield','passwd')->label('Password')->size(20);
>     $w->element('Textfield','email_address')->label('Email')->size(40)->value($user->email_address);
>     $w->element('Select','team_id')->label('Team')->options(@teams)->selected($user->team_id->id);
>     $w->element('Select','roles')->label('Roles')->options(@roles)->
>         multiple(1)->size(3)->selected(@role_ids);
>     $w->element('Submit','submit')->value('submit');
>
>     # Return the widget
>     return $w;
> }

Are you using Catalyst-Plugin-HTML-Widget's widget_result() method to
create the result object?
If so, you need to set $w->indicator() to something. Normally, just
the name of a field who's presence guarantees the form has been
submitted. I normally use the name of a hidden field, so I know it'll
always have a value.
You can also set it to a code-ref, for more advanced calculation.

I think I've improved how it's handled in HTML::FormFu - this logic is
in the core, rather than a plugin - and it you don't set indicator()
yourself, submitted() returns true if any known parameter names are
submitted.
('known' meaning something that matches the name of any field element
on the form object).

Carl



More information about the Html-widget mailing list