Examples » Specific Features

ID #1110

How do I enable 'as you type' validation?

FormMaker provides a number of options for controlling how fields are validated, and by default links this validation up to the submission actions available for buttons etc.

It is however possible to enable validation of each field as the user is entering their data.  To do this, you would need to add an 'onload' event to your page, with the following custom script content.

dojo.query('input[type=text], textarea, select')
    .onkeyup(function(e){hyf.validation.validateField(e.target);})
    .onchange(function(e){hyf.validation.validateField(e.target);})
    .onfocus(function(e){hyf.validation.validateField(e.target);});

You should now find that each field is validated as you enter or select the values.

If your page also makes use of dojo form widgets (such as a Filtering Select or Currency field) then you should add the following code to the onload event to make sure the validation of these also works in the same way.

var widgets = dijit.findWidgets(document);
for (var i=0; i < widgets.length; ++i)
{
    dojo.connect(widgets[i], 'onKeyUp', function(e){hyf.validation.validateField(dijit.byId(e.target.getAttribute('id')));});
    dojo.connect(widgets[i], 'onChange', function(e){hyf.validation.validateField(dijit.byId(e.target.getAttribute('id')));});
    dojo.connect(widgets[i], 'onFocus', function(e){hyf.validation.validateField(dijit.byId(e.target.getAttribute('id')));});
}

If required, you can place this code into a function in an external script file, and just call this new function from the onload event definition on the Field Details tab.

Tags: Dojo, validation

Related entries:

Last update: 2010-07-12 18:17
Author: Hyfinity support team
Revision: 1.1

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 0 (0 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ