Question
Different error messages on a Validate rule when tabbing vs. posting a page
I have a data class with an activity that does validation on a property of a class of the class by mapping that property to a validate rule in a step of the activity on the Property-Validate method. I have a section that has a control mapped to that propery. When I tab through the section and violate the rule I get the error message that was specified on the rule ("Enter a valid xyz"). When I post the form, the validation runs, but the error message is in the form "Invalid value specified for <property-name>. Value doesn't adhere to the validate: <validate-rule>. So it seems the post processing knows to call the validate, but doesn't have access to the error message specified on the rule. Can anyone shed light on to what's going on and how I might get post to display the right error message?
Thanks in advance!
***Moderator Edit: Vidyaranjan| Converted discussion to question***
James,
I am pasting in a snippet of the email you sent me because it describes your issue better than the post above:
I have a data class with an activity that does validation on a property of that class (pyContactEmail) by mapping that property to a validate rule in a step of the activity on the Property-Validate method (I didn’t create the activity or any of this stuff, I just inherited it). I have a section that has a control mapped to that property. When I tab through the section and violate the rule I get the error message that was specified on the rule ("Enter a valid Email"). When I post the form, the validation runs, but the error message is in the form "Invalid value specified for pyContactEmail. Value doesn't adhere to the validate: ValidateEmailAddress”. So it seems the post processing knows to call the validate, but doesn't have access to the error message specified on the rule. Can you shed light on to what's going on and how I might get post to display the right error message?
Looked into this and it is an interesting case, I figured out what is going on but it will take some explaining:
EditValidate rules run on the server, if the rule returns false then we put up an error message. Where does this message come from? It comes from a Rule-Message named PropertyInfo-EditValidate which has the message:
Invalid value specified for {1}. Value doesn't adhere to the Validate: {2}
Where 1 is the property name and 2 is the EditValidate rule name. So when you run your activity that validates everything is working as expected.
What is happening when you tab out? Where is the "Enter a valid Email" messasge coming from? First I thought maybe the ValidEmailAddress EditValidate rule was calling the theProperty.addMessage() method but that is not the case. So where is it coming from?
It ends up that the ValidEmailAddress EditValidate rule is special. When you use it Pega automatically adds client side JavaScript to validate the email and that JavaScript has the "Enter a valid Email" messasge hardcoded into it. Specifically the HTML Fragment rule csvalid contains the following JavaScript:
var ruleEditValidate_isValidEmailAddressMsgStr = "<pega:lookup property='pyWorkPage.pyMessageLabel' value='Enter a valid email address' mode='literal' />";
Cecil Howell, CSA | Senior Instructor | Pegasystems Inc.