Sunday, May 25, 2008

Dojo Dijit Form Validation

I thought form validation would be straight forward enough in dojo 1. It's not if your trying to avoid invalid markup. Form validation in dojo is indeed interesting. Some strange interaction has been developed for dijit.

I've wasted plenty of time this afternoon getting form validation onto a simple contact form. 2 input elements of type text and one textarea element. Nothing too crazy. Unfortunately there isn't any out of the box validation for textarea that I can see. All I need here is a validation rule of "textarea must not be empty". Nope nothing out of the box here.

Text input elements are the big surprise. The way it validates is when you change focus the inputs visual state changes. The input element gets a new colour and an icon. You then need to click on the input (give focus back to the input) and you will get a tooltip message giving the user feedback about what specifically is wrong with the current input.

I'm going to leave this validation on my project just because I think it's interesting and I've already invested the time getting this to work without invalid markup. I'll update this post with a link to the form once it's live.

1 comment:

Unknown said...

Hi, I'd just bumped into the same problem. Got it wired with dijit.form.ValidationTextBox fields, but have no clue how to handle other formelement types such as a textarea. (I haven't choosen dojo formvalidation to write workarounds...)
James, have you found a solution for validating textarea's in dojo?