Discussion
Validation question
On Slide 4 of the "Client Side Validation" lesson in section 8, there is the following:
[quote]
An edit validate rule in itself belongs to server side validation, a topic we will cover in the next lesson. But, many standard edit validate rules are emulated by an equivalent JavaScript function that can be run on the client side.
By default, the client-side format validation is enabled on all forms, so the fields using edit validate rules are validated before the form gets submitted.
[/unquote]
First of all, does this mean that a Edit Validate rule can be run client-side? Or just that for most standard edit validate rules the logic can be implemented using other client-side controls?
If so, is there anything we need to do to get an Edit Validate rule to check for an equivalent client side version, or is that embedded in the Edit Validate rule itself?
Hi,
an edit validate rule is basically Java code so it will never be executed on client side.
What it means is many OOTB edit validate rules have been implemented on OOTB js files in JavaScript so it is run on client side. The JS code can be used to do some formatting as well.
You don't have to do anything for your edit validate rule to call the JS, see below.
If you want to make a quick test, add the SSN edit validate rule to any Text property. Run a case and type in: 111111111 (9 * 1) and click somewhere else.
Your text is automatically, using JS, formatted to: 111-11-1111
That said, if you want to create your own feature, you will have to write your own JS code and reference it in your harness.
Example:
Create a property called PP
Create an edit validate rule called ValidatePP saying:
if ("damien".equals(theValue)) {
return true;
} else {
theProperty.addMessage("Don’t phunk with my property");
return false;
}
Create a text file
/* PPValidation */
var ruleEditValidate_pp = new validation_ValidationType("ValidatePP", ruleEditValidate_ValidatePP);
ruleEditValidate_pp.addEventFunction("onchange", ruleEditValidate_ValidatePP);
//=====================PP_VALIDATION=============================
/*
@public- Validation function for ValidatePP Rule-Edit-Validate
This function returns the validation error object if the field is not "damien".
@param $object$object- The object which represents the input field
@return $object$validation_Error - Validation Error object
*/
function ruleEditValidate_ValidatePP(object)
{
if("damien" != object.value) {
return display_getValidationError(object, "this '" + object.id + "' field is not valid" , " it has to be damien", true);
}
}
Reference your JS file from your harness in the Scripts and Style tab
Damien