Check documentation for the latest version of dhtmlxSuite Validation DHTMLX Docs

Validation

Before saving data on the server you can validate it and assign a handler function for any gotten response.

Shortly, validation contains 2 key points:

  1. value checking
  2. processing in case of validation error

Сommon

To implement the server-side validation of incoming data you can use the following events:

The beforeProcessing event occurs for all types of operations while other events occur only for related operations, i.e. you can set different validation rules for different operations or for all of them at once.

The event will receive DataAction object as the parameter. This object can be used to retrieve related data and allow/deny an operation (please note, it contains only the data which was received from the client side, not all the data related to the record).

Value checking

To check the value of a field you should use the method get_value()

<cffunction name="validate">
    <cfargument name="data">
    <cfif ARGUMENTS.data.get_value("some") eq "">
        ...
    </cfif>
</cffunction>
<cfset conn.event.attach("beforeProcessing",validate)>

Processing in case of validation error

In case of error you can choose one of two ways:

1) Use the predefined methods for error processing on the client side, i.e. set:

  • data.invalid() (invalid record will be highlighted by the bold font)
  • data.error() (invalid record will be highlighted by the red bold font)

The difference between methods in question consists just in the way of highlighting.

<cffunction name="validate">
    <cfargument name="data">
    <cfif ARGUMENTS.data.get_value("some") eq "">
        <cfset ARGUMENTS.data.invalid()>
    </cfif>
</cffunction>
<cfset conn.event.attach("beforeProcessing",validate)>

2) Assign your own processing on the client side through the dataProcessor's method defineAction() (see details here)

dp.defineAction("invalid",function(sid,response){
var message = response.getAttribute("message");
alert(message);
return true;// return false to cancel default data processing at all
})

Custom status

You can change the returned status and set your own one by means of the method set_status(). In this case any default processing (no matter, if the defineAction() method will return true or false) will be cancelled and you will specify data processing fully on the client side.

Server side

<cffunction name="validate">
       <cfargument name="data">
       <cfif ARGUMENTS.data.get_value("some") eq "">
                 <cfset ARGUMENTS.data.set_status("my_status")>
       </cfif>
</cffunction>
<cfset conn.event.attach("beforeProcessing",validate)>

Client side

dp.defineAction("my_status",function(sid,response){
...
})

Adding custom information to response

You can send some custom information to the client side through the following methods:

Back to top