User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
en:adminmanual:businessmappings:validations [2020/02/06 00:57]
joebordes [Activating the validation maps]
en:adminmanual:businessmappings:validations [2020/06/30 23:17] (current)
joebordes [Validation Business Mapping]
Line 111: Line 111:
     * restrictions:​ filename, validation test name, function name and label to show on error (will be translated)     * restrictions:​ filename, validation test name, function name and label to show on error (will be translated)
     * parameters: parameters can be passed to custom functions using the parameters-parameter directives ​     * parameters: parameters can be passed to custom functions using the parameters-parameter directives ​
- 
-<WRAP center round info 100%> 
-All of the rules above accept an optional directive named __message__ where you can set the error message you want the user to see when an error on that field happens. If this is not established a standard error message will be returned. Inside this message you can use the curly brace __field__ tag to indicate where you want the field name to appear: 
-  <​message>​This is my custom msg for field: {field}</​message>​ 
-</​WRAP>​ 
  
 <WRAP center round info 100%> <WRAP center round info 100%>
Line 129: Line 124:
 these parameters will be sent as a name indexed array to the function these parameters will be sent as a name indexed array to the function
 </​WRAP>​ </​WRAP>​
 +
 +===== Validation Message =====
 +
 +All of the rules above accept an optional directive named __message__ where you can set the error message you want the user to see when an error on that field happens. If this is not established,​ a standard error message will be returned. Inside this custom message you can use the curly brace __field__ tag to indicate where you want the field name to appear:
 +
 +<code XML>
 +  <​message>​This is my custom msg for field: {field}</​message>​
 +</​code>​
 +
 +Besides this option, which covers almost all the use cases, we have run into an edge case where we needed the message to be dynamically set. The problem with this is that the way the valitron library works we need to give it all the rules and messages before we start but in this case, we didn't know the message until the validation was launched. So we added support for defining the message before validating the rule for custom functions.
 +
 +To retrieve the message to be used, the validation map will look for a function with the same name as custom function concatenated with the string "​GetMessage"​. So, if we have a custom rule named "​validateFlowStep"​ and we define another function named "​validateFlowStepGetMessage",​ then the validation map will execute this second function giving it the same parameters as the validation function plus the current validation message. This way your custom validation function can determine which message to return. This is almost like launching the validation twice, so it comes at a price.
 +
 +You can see an example of this in the [[https://​github.com/​coreBOS/​ProcessFlowPerspective|BPM Process Flow Perspective]]. Look in the Process Flow module for the validateFlowStep script.
  
 ===== Activating the validation maps ===== ===== Activating the validation maps =====