Support Article
Need to remove the input feild text from Pega default error msg
SA-3747
Summary
When a integer type or boolean type, etc property is used and if a text value is inserted during runtime,
a message saying "<Input> is not a valid decimal value" is displayed.
The requirement is
1. Show only the text and not the property value, i.e., "This is not a valid decimal value"
2. Show text in Thai Language
Resolution
1. Save as the Customvalidators HTML Fragment in user ruleset.
2. Customized the numeric_decimal function in order not to get input value.
Please find below code.
<script>
var numeric_decimal = new validation_ValidationType("decimal", numeric_isDecimal);
numeric_decimal.addEventFunction("onchange", numeric_isDecimal);
function numeric_isDecimal(object){
//var x = removeCommas(object.value);
var x = removeSeparator(pega.control.PlaceHolder.getValue(object), grouping_separator);
if(null == x || "" == x)
{
return;
}
// var x = object.value;
// var decimals = numeric_occurence(x, ".");
var decimals = numeric_occurence(x, decimal_separator); //
// Regular expression for numbers
// The value can have numbers between 0-9 and '-', ',' and '.' symbols
//var nonNumbersMatch = /[^0-9-.,]/g;
var nonNumbersMatch = new RegExp("[^0-9-" + grouping_separator + decimal_separator + "]", "g");
var illegalChars = x.match(nonNumbersMatch);
if((null != illegalChars) || (decimals > 1))
{
object.value = "";
return display_getValidationError(object, "", numeric_decimalMsgStr);
}
if(object.decimalPlaces != undefined)
{
var decimalPlaces = parseInt(object.decimalPlaces);
if(!isNaN(decimalPlaces))
{
x = numeric_ensureDecimalPlaces(x, decimalPlaces);
}
}
// If the value should be reformatted enable this line
//object.value = numeric_reformat(x);
}
</script>
The above snippet is able to handle the validation requirement of not displaying the entered text at the client-side
Server Side Validation
a. The DecimalValueBadFormat Message rule should be customized as follows :
Remove the paremeter from the Message Parameter section and also the {1} from the message field. This will ensure that the entered text is not displayed in the error message.
b. The above Message rule is applicable only to the Decimal Validation Message. The similar approach can be followed for the other controls as well.
* Decimal - DecimalValueBadFormat
* Date - InvalidDateValue
* DateTime - InvalidDateTimeValue
* Number - NumberValueBadFormat
* Integer - IntegerValueBadFormat
Published January 31, 2016 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.