Evolutility.org 4.1
 

Form validation

Evolutility automatically generates Javascript for field validations on the client. This Javascript executes when the user clicks the "Save" button.


 

Generic validation

Validation is determined by the field properties (XML attributes):

  • Type - Text, Integer, Decimal, Date...
  • Required - Must have a value.
  • Min - Minimum value allowed.
  • Max - Maximum value allowed.
  • MaxLength - Maximum length.
  • RegExp - Regular expression to verify.

If the form doesn't pass validation, a messages is generated in the locale of choice (without additional text to enter) and shown to the user in a lightbox.



In addition, after the user clicks OK and the lightbox disappears, fields not passing the validation are flagged in red on the form.


 

Custom validation

It is possible to add custom validation to Evolutility forms by using Javascript.

This is a 2 step process:

  • Add the hook to the field by using the jsvalidation attribute to specify the Javascript method name (only the name, no parameters).
  • Add the Javascript to the ASP page or to Evolutility.JS library if you plan to re-use it on multiple pages.

The Javascript function will be passed 2 arguments: the field ID and the field label. It needs to return a string with the error message if the validation is not correct, and return null otherwise.

For example to only allow company names starting with "E":

In the XML

<field label="Company" ... jsvalidation="StartWithE" />

In Javascript

function StartWithE(fID,fLabel){
   var v = $(fID).value;
   if (v.length>0 && v.substr(0,1) != "E")
      return 'The field "'+fLabel+'" must start with "E".';
}

Second example this time we want to force at least one of the 2 "Home phone" or "Mobile" to have a value.

In the XML

<field label="Home phone" ... jsvalidation="TelHome" />

In Javascript

function TelHome(){
   if ($("EVOLU_phoneh").value == "" && $("EVOLU_phonem").value == "")
      return 'At least one of "Home phone" or "Mobile" must have a value.';
}

In this second example, we used hard-coded field names and labels so we didn't give arguments to the custom function. Also, even though 2 fields are involved in the validation, we only needed to declare the rule once in the XML (on the field that will be flagged in red if the test fails).

See examples of custom validation.