Question
Societe Generale
IN
Last activity: 16 Dec 2015 12:23 EST
Client side validation using run script
Is it possible to handle the client side validations using Pega OOTB control events (like OnChange event Action run script).
If so could any one let me know the steps to validate and set message at property level on the screen.
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
JPMC
IN
Hi,
How about using edit validate rule, with client side validation configured.
refer: https://community.pega.com/sites/default/files/help_v718/procomhelpmain.htm format validation
for format validation refer:
https://community.pega.com/sites/default/files/help_v718/procomhelpmain.htm format validation
and
https://community.pega.com/sites/default/files/help_v718/procomhelpmain.htm format validation
Societe Generale
IN
Thanks for the quick response Ashish.
This we have tried and it was working but we should not have the validation tagged to property as edit validate rule.
We would like to use the same property with validation and without validation in situation basis and we have many properties used in this manner. So could you please let us know the solution to achieve using run script.
Thank you.
JPMC
IN
Hi Subramanyam,
How about writing a custom Java script function and call that through run script. And in that JS function do validation and through alerts for erros.
This will prompt alerts to endusers for onchange events...
However also configure server side validation for better security as this way many not restrict user to submit the form, but helpful to users to get a client side response about errors.
Societe Generale
IN
Your suggestion is valid and it works to show the message as alert but here i have a requirement to show the message on the screen it self.
Could you please suggest me on this point.
Thank you.
Pegasystems
US
It sounds like a similar situation to what you want occurs when the out-of-box "save" feature and "submit" are compared.
Suppose you have a required field called "street address". If user presses "submit" before filling this in, you want to see a screen error saying something like "street address is required".
However, if the user presses "save" before filling the required street address field in, you would want to quietly save the work object since the user may be leaving for the day with the intention of filling in the street address tomorrow.
So this is a good example of a field whose validation rules are dependent, and we want to allow the blank field if "save" is chosen, but demand a value for the field when "submit" is chosen.
Can you design your validation similarly to this situation to provide for your dependent validation ? /Eric
Societe Generale
IN
Thanks for the response Eric.
I am not wrong the scenario which you explained can be handled only in server end.
In my case for example consider that i have the "street address" used in two different sections which should behave like with validation in one section and without validation in another section and i would like to use one property that to with client side validation.
I think this can be achieved using On change -> Run script. Here i would need to set the message on screen (not as js alert).
I tried to use the code of Edit validate to set the message on property as below but i couldn't get what is the object here. Please suggest.
return display_getValidationError(object, "Error Message", "", true);
Societe Generale
IN
Could any one answer for the above comment...?
-
Thota Swetha
GovCIO
US
Hi Subramanyam,
If you want to set the validation message on a property using EditValidate, we have many OOTB rules on the same. Kindly check the rule:ValidateOperatorID and is used in property:pyUserIdentifier. Below is the sample code used in that edit validate rule. Let me know, if you are not looking this kind of code snippet for your req.
-------------------------------------------------
String ClassName = "Data-Admin-Operator-ID";
ClipboardPage parentPage = theProperty.getParentPage();
if (!parentPage.getClassName().equals(ClassName))
return true;
ClipboardPage pgOpId = tools.createPage("Rule-RuleSet-Name","");
boolean valid = true;
if (!theValue.equals(""))
{
pgOpId.getProperty("pyRuleSetName").setValue(theValue);
String strResolvedKey;
try
{
strResolvedKey = ((PegaDatabase)tools.getDatabase()).findHandle(pgOpId);
if (strResolvedKey != null)
{
theProperty.addMessage("OpIDShouldNotEqualRuleSet\t");
valid=false;
}
}
catch (DatabaseException e)
{
}
}
--------------------------------------------------------------------------------------
Societe Generale
IN
Thanks for the response Ravi,
It would be better if you provide me the code which runs on client side and that should be configured on OnChange event of the property.
I am not sure whether its possible in Pega.
Updated: 16 Dec 2015 1:05 EST
GovCIO
US
Hi,
As per your earlier reply, please see the below details. Check if this works for you.
---------------------------------------------------------------
/*
@public- Validation function for integer
This function returns the validation error object if the field is not a valid integer value.
@param $object$object- The object which represents the input field (textbox)
@return $object$validation_Error - Validation Error object
*/
function numeric_isInteger(object){
//var x = removeCommas(object.value);
var x = removeSeparator(pega.control.PlaceHolder.getValue(object), grouping_separator);
if(null == x || "" == x)
{
return;
}
// Regular expression for integers
// The value can have '-' item 0 or 1 time ((\-)?) and any number of digits afterwards (d+)
var reInteger = /^(\-)?\d+$/;
var legalInteger = x.match(reInteger);
if(legalInteger == null){
return display_getValidationError(object, "", numeric_integerMsgStr);
}
//If the integer should be reformatted, enable the following line
//object.value = numeric_reformat(x);
}
------------
Also, check the HTML fragment - csvalid. This is used for client side validations, I remember. Analyze this whole fragment and see if any clue comes in your mind for your req.
Thanks,
Ravi Kumar.
Societe Generale
IN
Hi Ravi,
I have used the same kind of code running in run script from the control but i could not get what is the object in the below statement. I think its a property reference. Here i would like to know how i can pass this as a parameter.
return display_getValidationError(object, "", numeric_integerMsgStr);
GovCIO
US
Hi Subramanyam,
To be honest, I never exposed on this function and the parms used. Just give a try with below snippet and not sure whether this will work or not. We used to write like this earlier in V4, V5.
<input type="textbox" class="textbox" ID="$PpyWorkPage$pLoB" name="LoB" onclick="setValue(this.ID)" value="20" />
Thanks,
Ravi Kumar.
GovCIO
US