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

Mario Minati mario.minati at googlemail.com
Tue Mar 13 13:56:29 GMT 2007


Am Dienstag 13 März 2007 10:42 schrieb Carl Franks:
> 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!

Just for my information, what's wrong with it?
Double coding the logic?
Better fall back on existing libraries?

> It means that all regex constraints would have to be pcre-compatible,
> so that they can run in JS.

Aren't they? Are the differences between pcre and perl regex handling that 
big? At least when I look at what Regex::Common produces it looks like it 
would work with JS, but it's just a stomake feeling I don't know by hard.

> It also doesn't really allow for onblur or onchange checks.
That's a problem, but Dojo supports an onchange handler that does what i 
expects to do, but in that case the form elemens had to be dojo form 
elements.


> 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!

I think the handing with / for JS libraries must be deeper inside. 
Maybe there could be a way useing the libs by replacing the templates, that 
way we also have support for js libs that don't support the creation of forms 
and validations out of markup.

As wth Dojo (the one I'm useing) the form elements need to have special tags 
to be recognized.
I think the hooking should start more deeply in a kind of before_this and 
after_that calls and in a more general form which could be used for JS libs 
but also for other things.
Maybe there could be a Plugin directory which could be used by 
$form->load_plugin('Dojo'); and the rest is done by the Plugin by recognizing 
itself for the hooks needed. This way all necessary attributes could be set 
before the form is processed or stringified.

Greets,
Mario



More information about the Html-widget mailing list