-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,80 @@ | ||
# Form Validation | ||
|
||
There are several ways how you can validate the user input before the form is processed by the Imixs Workflow Engine. | ||
The following section provides an overview of the various possibilities. | ||
|
||
|
||
|
||
There are several ways how you can validate the user input before the form is processed by the Imixs Workflow Engine. | ||
The following section provides an overview of the various possibilities. | ||
|
||
## Required Inputs | ||
|
||
|
||
With the tag `required` a mandatory input is defined: | ||
|
||
<item name="order.name" type="text" label="Description:" required="true"/> | ||
<item name="order.name" type="text" label="Description:" required="true"/> | ||
|
||
The input field is marked with a '*' and an error message is shown if no field value was added on submit. | ||
|
||
<img class="screenshot" src="validation-01.png" /> | ||
The input field is marked with a '\*' and an error message is shown if no field value was added on submit. | ||
<img class="screenshot" src="validation-01.png" /> | ||
|
||
### Disabling Validation of Required Inputs | ||
|
||
You can also disable the required validation for specific events like a 'Cancel' event by adding the following validation defintion into the correspondign event result: | ||
|
||
<validation name="required">false</validation> | ||
<validation name="required">false</validation> | ||
|
||
<img class="screenshot" src="validation-04.png" /> | ||
<img class="screenshot" src="validation-04.png" /> | ||
|
||
### Confirm a Event Action | ||
|
||
To force the user to confirm a event action you can optional add the Validation-Confirm Rule: | ||
|
||
<validation name="confirm">Are you sure to cancel this request?</validation> | ||
|
||
<validation name="confirm">Are you sure to cancel this request?</validation> | ||
|
||
## Validation Rules | ||
|
||
The required tag is a simple way to define a validation. With the help of the [Imixs Rule Plugin](https://www.imixs.org/doc/engine/plugins/ruleplugin.html) you can also define more complex business rules. For example you can verify if an input value has a minimum length: | ||
|
||
``` | ||
var result={}; | ||
if (workitem['order.number'][0].length<5) { | ||
if (workitem.getItemValueString('order.number').length<5) { | ||
result.isValid=false; | ||
result.errorMessage='The order number must have at least 5 digits!'; | ||
} | ||
``` | ||
|
||
You can place this rule in the Rule Property of the corresponding workflow Event: | ||
|
||
<img class="screenshot" src="validation-03.png" /> | ||
<img class="screenshot" src="validation-03.png" /> | ||
|
||
The error text is shown if the validation faled: | ||
The error text is shown if the validation failed: | ||
|
||
<img class="screenshot" src="validation-02.png" /> | ||
<img class="screenshot" src="validation-02.png" /> | ||
|
||
See the section [Imixs Rule Plugin](https://www.imixs.org/doc/engine/plugins/ruleplugin.html) of the Imixs Workflow Engine for more details about using business rules. | ||
|
||
### Validation of Comments | ||
|
||
In most cases you want to force the user to enter a comment if she reject an approval. This can be done with the following business rule: | ||
Or testing a number size: | ||
|
||
``` | ||
var result={}; | ||
var refField="txtcomment"; | ||
result.isValid=true; | ||
if ( ( workitem.get(refField) == null || ''==workitem.get(refField)[0]) ) { | ||
if (workitem.getItemValueDouble('order.amount')<1.0) { | ||
result.isValid=false; | ||
result.errorMessage='Please enter a comment.'; | ||
result.errorMessage='The order amount must be more than 1 EUR!'; | ||
} | ||
``` | ||
|
||
See the section [Imixs Rule Plugin](https://www.imixs.org/doc/engine/plugins/ruleplugin.html) of the Imixs Workflow Engine for more details about using business rules. | ||
|
||
### Validation of File Attachments | ||
### Validation of Comments | ||
|
||
Using the [Imixs Rule Plugin](https://www.imixs.org/doc/engine/plugins/ruleplugin.html) it is also possible to validate more complex data. For example you can ask if at least one document was attached to the form: | ||
In most cases you want to force the user to enter a comment if she reject an approval. This can be done with the following business rule: | ||
|
||
var result={}; | ||
result.isValid=true; | ||
if (workitem.getItemValueString('txtcomment') == '') { | ||
result.isValid=false; | ||
result.errorMessage='Please enter a comment.'; | ||
} | ||
|
||
var result={}; | ||
if (workitem['$file.count'][0]==0) { | ||
result.isValid=false; | ||
result.errorMessage='Please attache the Purchase Order Document!'; | ||
} | ||
### Validation of File Attachments | ||
|
||
Using the [Imixs Rule Plugin](https://www.imixs.org/doc/engine/plugins/ruleplugin.html) it is also possible to validate more complex data. For example you can ask if at least one document was attached to the form: | ||
|
||
var result={}; | ||
if (workitem.getItemValueInteger('$file.count')==0) { | ||
result.isValid=false; | ||
result.errorMessage='Please attache the Purchase Order Document!'; | ||
} |