Form Validation v3.0b
As mentioned yesterday I am re-working my old Form Validation database. Here's what v3 looks like now.
It's experimental at the moment, but it works. If you're using the old v2 methods then all you need to do to upgrade is add effects.js, prototype.js and overwrite validation.js with the newer version. There's no need to change anything at the Form level.
Apart form cosmetic changes I think I need to rewrite the whole thing. When I wrote that code all those years ago it was a case of simply making it work and little thought was given to the actual code. It seems nowadays that the way people write JavaScript has changed. Everything gone all Object Orientated. In the current code validation is a case of:
if ( validateRequiredFields( f, a ) ){
Now it's more normal to expect something like:
if ( Form.validate() ){
Whereas before the settings and properties were global variables they are now properties of the Object we define to handle the validation functions.
While I managed to do this style of coding in the code for the Name Picker demo I have to admit I don't fully understand it all the time. Before I rewrite the validation code I think I might stick my head in my JavaScript manual. Bear with me. If you want the validation database as it stands now, let me know and I'll mail it over.
I think I may have mentioned here once before (or maybe it was on my blog), an indepth analysis of Scriptaculous will give you some ideas and patterns for good OO javascript. It's very much a reverse engineering approach, but it is a current up to date implementation of OO Javascript. I used it as a template when I took some older style JS widgets OO to make them easier to implement in batches on a form.
{Link}
Thanks Jerry. Good idea. Reverse engineering is how I've always "learnt" things in the past. In this case though I don't know if I'll ever get to the point where I understand what and why I'm doing. I'll do a bit of background reading first me thinks.
Hi Jake, Can you pls mail me the new Form Validation Example. Thanks a lot
Any example for fields thats not mandatory but if user entered anything, it will check if it's numeric? It would be good if the validation can check for the number of checkbox if required.
Would it not be better to list all the required fields at the top and then just highlight each field in red? If the form is really long the user might not know that it hadn't been submitted, as the error could be out of the screen.
I normally show all errors in red at the top of the screen, show a messagebox listing all errors, and also set the focus to the first mandatory field.
found on digg today : {Link}
I would like a copy of the db as it stands now, thanks! This will look very good for an appI amrevising...
Hi Jake, could you email me the Validation example database? thanks!
Hi Jake,
Looks great, if you get a chance I would love to take a look at the code.
Thanks again
Hi Jamille,
You can find it here:
{Link}
Jake
I am trying to validate a url in my form using javascript but I couldn't! Any help?
Jake- great stuff. I would love a copy of the current nsf if you might. Thanks.
Hi Tom. This code is in the "DEXT" database, which you can download from the Sandbox tab above.
Jake,
How would you pass a test function to determine that at least three check-boxes have been selected?
Hi Louis. Take a look at the "custom option" in the demo:
http://www.codestore.net/apps/validation30.nsf/contact?OpenForm
You could write your own little function to count the number of selected checkboxes and return true/false.