[html-formfu] Validator vs Constraint
Carl Franks
fireartist at gmail.com
Thu Mar 13 09:49:39 GMT 2008
On 06/03/2008, Andreas Marienborg <omega at palle.net> wrote:
> To follow up even further, what is the rationale behind validators
> only running if all constraints pass? It makes for a rather
> unintuitive process for the users? They get 3 red boxes, fix them, and
> _then_ get another red box on something that seemed fine.
>
> I can understand validators only running for fields where constraints
> pass, but only after all seems a bit strange.
I originally made each step (constraints, inflators, validators,
transformers) an "all or nothing" effort because:
- firstly for inflators - they could be considered relatively
expensive, and so if there's any constraint errors on *any* fields,
you'll probably just be re-displaying the form again, and so probably
wouldn't want any inflators run.
- validators - I originally thought would be used for higher-level
"business logic" involving multiple fields. If you're needing to
validate on a single field, and it doesn't need inflated - then you
may be as well using a Constraint instead.
If you wanted validators to run if there's constraint errors on
unrelated fields, there would need to be a mechanism for the validator
to state which other fields should also be error-free (much like
others() on some constraints).
I think this would probably be a bit too much complexity, and error
prone, as the field list would need to be kept in sync with the
validation code.
Currently the only validator is HTML::FormFu::Validator::Imager::Size.
I've never yet needed to write any custom validators.
I hope this explains how we got where we are :)
Carl
More information about the HTML-FormFu
mailing list