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

Common

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()

class validateBehavior extends ConnectorBehavior{
    @Override
    public void beforeProcessing(DataAction action) {
        if (data.get_value("some").equals(""))
        ...
    }
}
 
conn.event.attach(new validateBehavior());

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 in bold font)
  • data.error() (invalid record will be highlighted in red bold font)

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

class validateBehavior extends ConnectorBehavior{
    @Override
    public void beforeProcessing(DataAction action) {
        if (data.get_value("some").equals(""))
            data.invalid();
    }
}
 
conn.event.attach(new validateBehavior());

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 you own by means of the method set_status(). In this case any default processing (doesn't 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:

class validateBehavior extends ConnectorBehavior{
    @Override
    public void beforeProcessing(DataAction action) {
        if (data.get_value("some").equals(""))
            data.set_status("my_status");
    }
}
 
conn.event.attach(new validateBehavior());

Client side:

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