Let us say you have a form in which a field is a required field(mandatory) based on selections of two other fields in the form, then it gets really tough to get the rules right.
Here is an example.
- An employee is transferred to a new organization in the company, with or without a promotion(optional).
- Let us say the same screen also allows promotions to be done without any org transfer.
- The third field, namely "myfield", is an optional field most of the time, except when either or both of the above actions are done at the same time.
Validation Rules in words.
- Field 1 (neworg) -> If "neworg" value is non-null and not same as "prevorg", then "myfield" is required.
- Field 2 (newgrade) -> If "newgrade" is equal to 'A', then "myfield" is required, otherwise not.
- Field 3 (myfield) -> Required if either of the above condition is valid.
Let us say this form also has another field namely "prevorg" to hold the user's original org name.
<field property="myfield" depends="validwhen" >
....
<var-value>
(
(
(
(neworg == prevorg) or (neworg == null)
) and (newgrade != 'A')
) or (*this* != null)
)
</var-value>
...
Note carefully that negative of written rules is realized as the "var-value".