We’ve had a couple instances in which our payment system identifies records in Salesforce that have 3 decimal places instead of 2 ($1.075 instead of $1.08). Skuid rounds to 2 decimals based on the field metadata and displays that in read mode, but does not block the user from entering more digits in edit mode and saves the user’s entry into the database regardless.
I know Salesforce allows the API to enter any length number, so it is understandable why Skuid can do this. How might I block users from entering more than the field’s allowable number of decimals in the first place?
Right now Skuid allows users to type in as many decimal places as their heart desires. Then it will show the decimal places chosen by the user on the Skuid page, here:
But it will only save the amount specified by Salesforce and will round to whatever is appropriate.
For example, if I have my settings to view 3 decimal places, Salesforce only allows 2 based on my configuration, then I input 1.1119, the value salesforce will attain is 1.11 and Skuid will show 1.110.
Are you hoping to have skuid throw an error when the user saves past the specified decimal places? Do you want to get rid of the rounding rules?
If it’s set like the example above, and the customer inputs 1.8888888, what would you like the UI to do?
But it will only save the amount specified by Salesforce and will round to whatever is appropriate.That's not the behavior I am seeing. If it is set up like above and the customer inputs 1.8888888, Skuid displays 1.889, Salesforce standard UI displays 1.89, and a SOQL query returns 1.8888888. The unrounded value is being saved to the databse - that's what I want to prevent from happening.
For example, if I have my settings to view 3 decimal places, Salesforce only allows 2 based on my configuration, then I input 1.1119, the value salesforce will attain is 1.11 and Skuid will show 1.110.
Best scenario: disallow the user from typing more than 2 decimal places
Acceptable scenario: allow user to enter any number of digits, but save the rounded value
You can use a custom renderer like this:
skuid.snippet.registerSnippet('DecimalScaleLimit',function() { var field = arguments[0], $ = skuid.$, value = arguments[1]; skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value); if (field.mode === 'edit') { var scale = field.metadata.scale; var input = field.element.find(':input'); // checks for a number with or without the decimal var decimalRegex = /^d+(.d+)?$/; skuid.utils.delayInputCallback(input,function(newValue, oldValue) { var val = input.val(); if(val) { console.log(val); if(decimalRegex.test(val)) { if(val.indexOf('.') !== -1 && val.split('.')[1].length > scale) { var num = Number(Math.round(val+'e'+scale)+'e-'+scale); console.log(num); input.val(num); } } } }); } });<br>
This pattern is used for static resources. If you want to use this as an inline snippet then you can remove
skuid.snippet.registerSnippet('DecimalScaleLimit',function() {
and the beginning and
});
from the end
This is remarkably observant of you. I have no idea. I checked it after clearing the cache too. From my understanding, this means that somehow salesforce is keeping the information. But that is just a guess. I’ll ask a developer to see what the fine print is.
The strange thing is that if I check it in salesforce outside of skuid, they have saved the number of digits that skuid has assigned if you go to edit it. But it shows you the rounded number you’ve established in Salesforce. Bizarre behavior, but accurate to it’s rules.
Is this creating some form of problem for you? Do you have a business case that this is affecting?
Yes - users can schedule outbound payments to our fulfillment partners, which are then imported by our payments system. That system throws an error if there are fractional cents, and our treasury team has to go back to the user and have them clarify the exact amount they need to send. This slows down the whole process and creates delays in paying our partners.
Thanks for asking a dev to check in on it! Looking forward to see what they say. I’ll try the snippet Pete suggested below for now
Thanks! I’ll use this for now, but hopefully a Skuid dev can identify and fix the core issue
Thank you for taking the time to explain this. I’ll see what I can do.
Update: works perfectly, thank you!
The functionality of adding client side validation has been on the developer’s list for a while now. It is slated to be released in a skuid update later this year. It’ll be months from now, but we’re excited to have that coming down the line eventually.
Great, looking forward to it!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.