Start page
Start page

Start page / Template development / Rules / Preconditions <IF/>

<IF/> Designing preconditions for rule execution

A validation takes place directly during the entry of a value into an input component. This means that the rule is performed every time the editor presses a key.

This behavior is not desired in all cases. In case of more complex requests or a very extensive rule definition, it might make sense to define a precondition for the execution of the rule.

Handling instructions are defined within an <IF/> section. This section must be defined within the tags that determine a restriction level and before the tags for a value determination.

In the process, the following applies for the definition of a precondition:

  • A precondition can be optionally defined in a rule. (If no precondition is defined, the rule is always performed.)
  • A Boolean value is determined through a precondition. If the precondition is fulfilled (TRUE), the subsequent rule sections are performed; if the precondition is not fulfilled (FALSE), they are not performed.
  • The precondition always refers to a certain property of the form element or of the form (e.g.,“was the form opened in the Content Store?”).
    For this purpose, the specification of a <PROPERTY/> tag within the <IF/> section is necessary. Through additional values can be derived. The value of the input component, for example, can be checked against certain regular expressions or against a comparison value.

Examples

Example 1) Language-dependent validation using a precondition

The definition of a precondition is ideally suited for a language-dependent validation. In the following example, only a certain branch of the rule is performed depending on the currently processed editing language. The input component “st_standard”, for which the rule is defined, permits the language-dependent specification of a DIN standard (for German (“DE”)) or an ISO standard (for English (“EN”)). Using the definition of a precondition, the rule checks in which language the form is being processed by the editor (language-dependent validation).

 

During the processing of the editorial language “DE”, the following precondition is considered to be fulfilled:

 <IF>
<EQUAL>
<PROPERTY source="#global" name="LANG"/>
<TEXT>DE</TEXT>
</EQUAL>
</IF>

In this way, the subsequent branches of the rule that check whether the entry of the editor corresponds with a correct DIN standard format using a regular expression are performed. As long as the condition is not fulfilled (FALSE), the instructions are executed within the <VALIDATION/> section:

...
<WITH>
<MATCHES regex="^DIN\ \d\d*$">
<PROPERTY source="st_standard" name="VALUE"/>
</MATCHES>
</WITH>
<DO>
<VALIDATION>
<PROPERTY source="st_standard" name="VALID"/>
<MESSAGE lang="*" text="No DIN standard given"/>
<MESSAGE lang="DE" text="Keine DIN-Norm angegeben"/>
</VALIDATION>
</DO>
...

For additional editorial languages, the rule definition is expanded by a rule that checks whether the entry of the editor follows a correct ISO standard format using a regular expression according to a fulfilled precondition:

...
<ON_SAVE>
<IF>
<NOT>
<EQUAL>
<PROPERTY source="#global" name="LANG"/>
<TEXT>DE</TEXT>
</EQUAL>
</NOT>
</IF>
<WITH>
<MATCHES regex="^ISO\ \d\d*$">
<PROPERTY source="st_standard" name="VALUE"/>
</MATCHES>
</WITH>
<DO>
<VALIDATION>
<PROPERTY source="st_standard" name="VALID"/>
<MESSAGE lang="*" text="No ISO standard given"/>
<MESSAGE lang="DE" text="Keine ISO-Norm angegeben"/>
</VALIDATION>
</DO>
</ON_SAVE>
...

Example 2) Preventing the exceeding of values using a precondition

In an additional form, there is one entry field each for a start date (“st_startDate”) and an end data (“st_endDate”). Using a dynamic form, an end data is automatically calculated and assumed in the input component “st_endDate” when the editor enters a start date (see the Calculate Date example).

In the process, an end date already entered by the editor should not be overwritten by the rule. To guarantee that the rule is performed only if the “st_endDate” input component is not already fulfilled, a precondition is defined:

        <IF>
<PROPERTY source="st_endDate" name="EMPTY"/>
</IF>

The following sections of the rule—that is, the calculation of a new date and the assumption of the new value in the input component “st_endDate”—are not fulfilled until this precondition is fulfilled.

<ON_EVENT>
<IF>
<PROPERTY source="st_endDate" name="EMPTY"/>
</IF>
<WITH>
<ADD value="2 weeks">
<PROPERTY source="st_startDate" name="VALUE"/>
</ADD>
</WITH>
<DO>
<PROPERTY source="st_endDate" name="VALUE"/>
</DO>
</ON_EVENT>

© 2005 - 2015 e-Spirit AG | All rights reserved. | Last change: 2015-02-18