[Catalyst] HTML::Widget - optional constraints
mjg17 at eng.cam.ac.uk
Mon May 8 13:50:04 CEST 2006
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.
More information about the Catalyst