[Fwd: [Html-widget] formfu validation proposals]

Carl Franks fireartist at gmail.com
Tue Mar 13 09:42:50 GMT 2007


On 13/03/07, Tobias Kremer <list at funkreich.de> wrote:
> > > I propose making it a lot more powerful and flexible, with the following
> > > steps:
> > >  * filter
> > >  * constrain
> > >  * inflate
> > >  * validate
> > >  * transform
>
> I was just wondering where one would hook in a jQuery (Prototype, Dojo,
> whatever) library that makes use of the defined constraints to check
> certain aspects of the form on the fly in the clients browser? This
> should not be a big deal but a really useful and cool thing IMHO. No
> current form library supports this out-of-the-box AFAIK - maybe
> HTML::FormFu will? :)

CGI::FormBuilder has a 'javascript' option, which will automatically
generate JS checks which run on 'onsubmit', and show a dialog message
if there's errors.
And I *really* don't want to go down that route!
It means that all regex constraints would have to be pcre-compatible,
so that they can run in JS.
It also doesn't really allow for onblur or onchange checks.

I've still to experiment properly with how best to handle this, but
one of my plans is to be able to force the error markup to be
generated, but with a 'disabled_error_foo' rather than a 'error_foo'
classname.
This will allow the JS to search for elements by that classname,
rewrite the classname if a check fails, and display the error message.
And by setting 'auto_constraint_class', that should provide the hooks
you need to write your own JS checks.

I'm still not sure though of how best to allow some form of JS checks
which can be loaded from the perl code.
Maybe different JS libraries will each need their own perl package for
each constraint.
So, for example, There would be:
HTML::FormFu::Constraint::Dojo::Required
HTML::FormFu::Constraint::JQuery::Required
and then have a setting such as 'auto_js_constraint', which if you set
to 'Dojo' and then add a 'Required' constraint, it'll automatically
look for the 'Dojo::Required'.

Anyway, I'm just making that up as I type it ;)
Still some ways to go!

Carl



More information about the Html-widget mailing list