[html-formfu] Conditional constraints

Carl Franks fireartist at gmail.com
Tue Dec 9 21:15:16 GMT 2008


2008/12/9 Ronald J Kimball <rkimball+formfu at pangeamedia.com>:
> I'm curious about what would be best practice for doing "conditional
> constraints", such as: if fieldA's value is 'foo', then fieldB is required;
> or if fieldA's value is 'bar', then fieldB must have the value 'baz'.  Have
> other people had to do something like this?  What would be a good way to
> accomplish it?
>
> Perhaps a constraint derived from HTML::FormFu::Constraint::_others, with
> some additional configuration available...

Check out $constraint->when()
http://search.cpan.org/~cfranks/HTML-FormFu-0.03007/lib/HTML/FormFu/Constraint.pm#when

If the docs aren't clear, there's examples in the test suite:
    t/constraints/constraint_when.t
    t/constraints/constraint_when.yml

Carl



More information about the HTML-FormFu mailing list