Question
Adept View
NL
Last activity: 17 Sep 2019 7:58 EDT
Restrict an user to certain decimal points
Hi,
I need to restrict a decimal property to 2 decimals (For ex; User should not be able to enter after 2.12). I tried using pyDecimalPrecision in property but that is not working as expected. It is rouding off to highest number.
Can any one know the exact solution on how to prevent user after entering two numbers after decimal.
-
Likes (1)
Hui sieng Aw yong -
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Adept View
NL
Thankyou everyone for your comments. They are very helpful.
I had written an edit input rule and solve my requirement.
TCS
IN
You can use integer,number or currency control and give decimal places 2 in read only format in presentation tab and enable checkbox "Display value using read-only formatting" .Using this user can enter any number like 23.2345 but once user leave focus it will get converted to 23.23 automatically.
Areteans
AU
Hope this helps you:
https://collaborate.pega.com/question/can-we-restrict-user-entering-decimal-values-decimal-property
https://community1.pega.com/community/pega-product-support/question/how-restrict-ip-decimal-property
Goldman Sachs Group Inc
IN
Hi,
Thank you for posting your question.
The functionality of "pyDecimalPrecision" Qualifier is to round of to the mentioned places.
This is achieved by passing the precision parameter to the "Decimal" control as below.
Hi,
Thank you for posting your question.
The functionality of "pyDecimalPrecision" Qualifier is to round of to the mentioned places.
This is achieved by passing the precision parameter to the "Decimal" control as below.
1. Open the "UserWorkForm" and add the below script.
<script>
$('#DecimalProp2').on('input', function () {
this.value = this.value.match(/^\d+\.?\d{0,2}/);
});
</script>
2. In the place of "DecimalProp2" you should add the element id of your property. You can find that using browser debugger tool as below.
Thanks,
Adept View
NL
Hi,
I have tested the javascript code it work like if i entered 12.4566 it returns 12.45
but my requirement is it does not allow to enter thrid number after decimal.
ex:12.45 after 5 if enter some thing it does not take input.
Goldman Sachs Group Inc
IN
Hi,
The above code I provided will not allow user to enter after two decimal values.
In the UserWorkForm replace the DecimalProp2 with your property ID.
This is working fine at my end.
Thanks,
Instellars Global Consulting Pvt.Ltd
IN
Hi Bharathi,
Could you please Provide Some screen shots?
1. Where we can open the "User Work Form"?
2. Where we have to write this Script Which you provide?
Thanks,
Goldman Sachs Group Inc
IN
Hi Parusharam,
UserWorkForm is a HTML Fragment rule belonging to Pega-UIEngine ruleset.
You can add the script in that rule.
Regards,
Pegasystems Inc.
US
Try this.
<script type = "text/javascript" >
document.getElementById("Prop").onkeypress = function(event) {
var charCode = document.getElementById("Prop").value.toString();
if (charCode.includes(".")) {
var numb = charCode.split(".")[1];
if (numb != null && numb.length > 1) {
alert("Only 2 decimal places allowed");
return false;
}
}
};
</script>
I tried this at my end and it seems to be working.
Pegasystems Inc.
US
Also, add a Null check before this, so that we do not get the console error messages in Developer tools for the screen which does not have this property.
Please find the attached code.
Accepted Solution
Adept View
NL
Thankyou everyone for your comments. They are very helpful.
I had written an edit input rule and solve my requirement.
Instellars Global Consulting Pvt.Ltd
IN
Hi Raghavendra,
I got the Same requirement, Could you please provide your Edit Input code at here what you have written. That would be a great help.
Thanks in Advance.
Adept View
NL
Hi parusharam,
please find the edit input rule. it is used to modify the the value entered by the user.
-
Rajeswari Gopal Nithya Soundarajan padmavathi palaniappan Vinay Meher Puvvada Nalina Ravibiruthoji and 1 More
Instellars Global Consulting Pvt.Ltd
IN
Thank you,
It's Working Fine.
i have created Edit Input rule by which you given the code.
-
Alaa Itani Thalacheru Ragadeepthi