[Html-widget] Offer of help / question about H::W status

Carl Franks fireartist at gmail.com
Fri Aug 4 13:08:03 CEST 2006

On 02/08/06, Bogdan Lucaciu <bogdan at wiz.ro> wrote:
> I might go a bit off-thread with this, but I noted some problems that
> might need fixing (and were not already discussed on the list):
> 1. You can't control the 'comment' by using a custom Container, unless
> you start modifying the label element (find the comment, remove it, move
> it somewhere else) . The comment's position is hardcoded in mk_label.
> This is useful , because I might need:
>  Phone number: [ input ] (don't forget the area code)
> CSS positioning might not be enough for most cases.

Maybe move the comment code out of mk_label() and into a new
mk_comment() that could be overridden?

> 2. I should be able to simply add a 'required' marker on elements with
> 'All' constraint, that does not interfere with the comment (like a red
> asterisk)

I don't think that's the way to do it - as the All constraint might be
applied to Hidden elements.
How about subclassing the base class H::W::Element to add a new
accessor, and do what you will with it during as_xml() ?

> 3. I should be able to put a callback constraints that run the
> constraint _once_ with all the elements as parameters. Now the callback
> is ran multiple times,  for every element.

I don't think this is correct.
The process() method in HTML/Widget.pm loops over the constraints, and
for each one, calls $constraint->process( $widget, \%params, $uploads

> 4. Grouping constraints (like Any or Equal) should not cause the error
> message to be displayed on every element, it's quite ugly. I'm not sure
> what the solution is, maybe only the first element in the group should
> show the error.

The simplest way I can think of doing this, would be to use css to
ensure that a particular name/constraint ID is never displayed.

It sounds reasonable to want the xml output like this though.
The extra elements would still be invalid, even though they wouldn't
display the errors.
I think I would prefer the constraints Any/All to have an accessor by
which you could state which element name you want to display the
The renderer could then call can() to see if the constraint supports
it, and then only if the element name matches, display the error.
This would provide the advantages of being both backwards-compatable,
and also providing more control than simply adding the error to the
first element found.

> 5. process should be able to track by itself  if the form was submitted
> (by using a hidden field for example). If I supply the request object it
> fires the constraint code even if the form was not submitted.
> Now I have to do the check myself:
> if ($c->req->params->{submitted}) {
>         $w->process($c->req);
> } else {
>         $w->process;
> }

If you set $w->indicator, then Catalyst::Plugin::HTML::Widget will
figure out itself that the form's been submitted.
If you don't use Catalyst, then you could create a helper for your
choice of framework, which mimics C::P::H::W's behaviour.

I hope this all makes sense, please let me know it not.


More information about the Html-widget mailing list