How to Create Complex Constraints


In most of the cases, the constraint definition possibilities are enough when defining a object variable.

For example, below, if the destination IP field is empty, the GUI rendering engine will pop up an error message


In some case, the constraint is more complex and may depends on a combination of several conditions that can involve several other variables.

For example, the 5 variables: params.av, params.webfilter, params.spamfilter, params.ips, params.scanport have the following dependency:

if params.av is set then params.scanport must be set if params.webfilter is set then params.scanport must be set if params.spamfilter is set then params.scanport must be set if params.ips is set then params.scanport is not mandatory

to solve this, it is possible to add custom constraint evaluation to the object definition.

The custom constraint is implemented as a smarty template:

{if !empty($params.av) 
    OR !empty($params.webfilter) 
    OR !empty($params.spamfilter)}
    {if empty($params.scanport)}
    Scan Port must be set

the evaluation of the constraint will be done when the user click on the form save button:


then, if the user sets the params.av variable but doesn't set the ScanPort, the GUI engine pops up the error: