How to Create Complex Constraints

Overview

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

Empty_field_simple_constraint_error.png

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
    {/if}
{/if}

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

Empty_field_complex_constraint_implementation.png

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

Empty_field_complex_constraint_error.png