a real showbreaker for fapi validation are the many ajax calls.
rules are usually pregex but js regex are in some cases severely different than php regex, so you can't use them.
one way to solve this is using xregxp.http://xregexp.com/. with that most of php regex work and it is quite fast. in huge site(many elements) it stays respomsive and you can literally show a hint while typing. i think that would be a leap for clientside validation. would remove the show breaker "to many ajax calls" for fapi.

note that i am not afiliated in any way with xregxp. so i am not promoting that particular engine. if you now something better: great!

CommentFileSizeAuthor
#8 clientside_validation.patch8.09 KBkaidawai

Comments

attiks’s picture

Version: 7.x-1.31 » 7.x-1.x-dev

I like the idea. We searched for a similar solution in the past, but couldn't find any proper solution. The major problem is that we either have to support all possible regexp one can write in PHP, or find a way to determine which need an AJAX callback.

kaidawai’s picture

understand this. thing is every regengine is slightly different. even different php versions are different.
that means you never get every possibility covered.

so for "user" provided regex there is allways a responsibility to test if they work. only with the js regex the difference is so huge that you have quite a hard time to find something that works even for simple things. additionaly you have differences between browsers.
so i would think that it is acceptable if very complicated regex need a second thought but easy to work a around(i asume people who create such complicated regex are able to do).

attiks’s picture

I think the only way to find out is to implement it as an optional feature: so AJAX callbacks standard, xregexp optional is the library is installed.

Patches are welcome ;p

kaidawai’s picture

maybe, i have to think about the "optional" part.
a) a codehighliter module has the engine included.
i have to check which version. old versions conflict in rare occasions with jquery.
b) see how much effort it is to make it optional. (you need some checkbox in the configuration fe or something)
i get back too you in a couple of days.
:P

attiks’s picture

The "optional" is to not force people to install it, don't worry about it too much if you can provide a patch I'm more than happy ;p

ramsegal’s picture

i think basically the module should support all the built-in rules of jquery validation plugin, that way there's no need to use ajax calls...am i wrong?

attiks’s picture

This is about custom regular expressions, and the fact that regexp in PHP aren't compatible with regexp in javascript. For now we use a custom AJAX callback rule that does the check on the server side, the idea is to 'translate' the regular expressions from PHP to javascript, hence the need for a helper library.

kaidawai’s picture

StatusFileSize
new8.09 KB

a first try.
i tried to make it errortolerant and with as little changes to the existing code as posible.
a) additional checkbox in the admin form: default off. should do nothing without enabling it.
b) if and only if it is on it looks sites/all/libraries/ for a dir xregexp with the libs.
c) if it can't find it there it looks in the module dir for this folder.
d) if it still didn't find it it just does nothing. (user can add the library in a different way e.g. another drual modul that has - at least on such module exists!)
e) if it cant find the lib it falls back to standart ajax.

the ugly part: to be able to switch between the two functions without big changes in the code i created the two functions explicit in javascript. this function within a function. looks a little funny if one is not used to javascript functions turning up in the middle of the code. so at least i moved them to the front of the surrounding function.

patch is attached.

attiks’s picture

Status: Active » Fixed

Great work, i did some minor cleaning but it works great!

Pushed to latest dev version

attiks’s picture

kaidawai’s picture

see comment there.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.