diff --git a/src/site/markdown/forms/validation.md b/src/site/markdown/forms/validation.md index 874aa97a..56a8d051 100644 --- a/src/site/markdown/forms/validation.md +++ b/src/site/markdown/forms/validation.md @@ -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: - + -The input field is marked with a '*' and an error message is shown if no field value was added on submit. - - +The input field is marked with a '\*' and an error message is shown if no field value was added on submit. + ### 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: - false + false - + ### Confirm a Event Action To force the user to confirm a event action you can optional add the Validation-Confirm Rule: - Are you sure to cancel this request? - + Are you sure to cancel this request? ## 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: - + -The error text is shown if the validation faled: +The error text is shown if the validation failed: - + -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!'; + }