[Html-widget] [Catalyst] HTML::Widget - optional constraints

Carl Franks fireartist at gmail.com
Fri Sep 29 16:07:01 CEST 2006

(originally posted to catalyst mailing list)

On 08/05/06, Michael Gray <mjg17 at eng.cam.ac.uk> wrote:
> Hi
> I'm playing with HTML::Widget.  I have a form with three fields for
> variants of the same info, only one of which is required.  So, the 'Any'
> constraint is useful.  However I want to do further checks on each of
> the fields, but only if the field actually contains a value.
> As things stand, all constraints are applied regardless, so my empty
> fields get tested (and fail).
> I can see a couple of options:
>  1) Add a skip_if_empty() accessor to HTML::Widget::Constraint and
>     implement the logic in HTML::Widget::Constraint::process().
>     Optionally cope with an 'EmptyOr_' prefix in
>     HTML::Widget::constraint(), akin to 'Not_'.
>  2) Write an HTML::Widget::Constraint::NotEmpty which takes a further
>     bunch of constraints to run on the listed elements only if they're
>     not empty, otherwise returning success.
> (or (3) use the Callback constraint and roll my own, but...)
> Any thoughts?  I'd be happy to try writing a patch.

Sorry for this being totally overlooked!

All constraints should pass if the values are either undef or the empty string
(meaning, the field was missing, or the field was empty, respectively).
This is by design: if the field is required, also use an All constraint.

Which constraints were you having this problem with, and does the
problem still exist?

I think the constraints need a bit of a cleanup, as they seem really
inconsistent whether they override process(), or define validate() and
use the default process(). It makes it more difficult than necessary
to work on them.
I might get time to look at that next week.


More information about the Html-widget mailing list