« FilteringSelect Pt 3. | Main| Setting up Dojo with Domino »

Using an Email Validation Widget

Category   
Bookmark : del.icio.us  Technorati  Digg This  Add To Furl  Add To YahooMyWeb  Add To Reddit  Add To NewsVine 

Best practices for writing Domino apps has you put a server-side validation on data input as well as client-side validation. Why both? Because there's nothing to keep the internet user from spoofing your form and submitting malicious data directly to your back-end, so you need server-side validation. Why client-side? For useability, it stinks to go through an entire form, submit it, and then get a bunch of errors that need to be fixed. It's nice to have immediate feedback.

Ok, so you've been doing Notes forever and you have a good @formula for your server-side email field. Now you're thinking, crud, I've got to take this thing and write it in javascript and then figure out how I want to display an error to the user...do I put it next to the field, do I pop up an alert box. Dang it...why do I have to go to all this extra work !!!

If you're using Dojo, you can make this part of your life simpler. More...

All you need to get a nice email field validator for the client-side is the following:
  1. Create a shared $$HTMLHead field and drop it in your form(s) where you're doing dojo. The field contains this:
    "<script type=\"text/javascript\" src=\"dojo.js\"></script>"
  2. In the JSHeader for the form, add this line:
    dojo.require('dojo.widget.Textbox');
  3. In the properties box for your email field, go to the HTML tab, fillin the "ID" field and the "Other" field. The "Other" field should have something like this:
    dojoType="EmailTextBox" widgetId="EmailAddress"
    email_field_properties.jpg
So what do you get for that minimal amount of effort? An email field whose initial background color is green, turns light red when the user starts typing and stays that way until a valid address is entered, at which point it turns green again. If the user tabs out of the field while an invalid entry is in there, a text message appears next to the field saying, "The value entered is invalid." NICE...client-side work is now done.

And guess what, the validation is probably better than what you would provide yourself. For example, it knows that .xyz is not a valid domain, and it also knows that both .au .co and .com ARE valid. I know my validations weren't that sophisticated.

Want to see it in action? Try it Email Widget Demo.

Download the zipped db here. Enjoy!

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)