Hi All,
i have floatingpoint field in my UI, i want to restrict user from typing values upto 2 decimal point and Below is my expected results
but what is the issue am facing is its allowing me to enter more values after decimal point and also if i give round values it's not taking .00 value.below is my code
a!floatingPointField( label: "Dental Premium (Annual)", labelPosition: "ABOVE", value: ri!intakePreminumDetails['recordType!{4d82eb7f-ba46-46a2-a7dc-969f4ffcf344}GSE_SCL Intake Premium Details.fields.{cef89c65-a133-4766-bbb5-93cbcceddcab}dentalPremium'], saveInto: { a!save(ri!intakePreminumDetails['recordType!{4d82eb7f-ba46-46a2-a7dc-969f4ffcf344}GSE_SCL Intake Premium Details.fields.{cef89c65-a133-4766-bbb5-93cbcceddcab}dentalPremium'], if(a!isNotNullOrEmpty(save!value),fixed(save!value,2),null)), },
my rule input source is recordtype. and which of data type as decimal and also in db its decimal(10,2) .note(am using external db (sql server management studio) using connected system)
Discussion posts and replies are publicly visible
Easiest to just use a Text Field and sanitize the input similarly to how you already are. You won't be able to prevent the user from typing some gibberish into the field, but you can at least instantly justify it.
Example provided: we're using "fixed" for the display-time to make sure all decimal places are DISPLAYED even when they are zero.
(note: you do not need to STORE these extra places in the "decimal" data, as it is actually impossible to do so - if it should be SHOWN to the end user, it's up to you to do that on the user-facing side.)
"Save into" is null-checked and truncated to 2 decimal places upon entry. As I mentioned originally, of course, nothing can really keep the user from entering extra spam digits after the decimal place, but they are not saved. I don't know of any good workaround for that unfortunately - if you were dedicated to it, you could look into using the "character count" feature, but I don't know if you'd be able to update it dynamically enough to account for different values ahead of the decimal point.
a!localVariables( local!testDecimal: null(), a!textField( label: "Fake decimal entry", refreshAfter: "KEYPRESS", placeholder: "Enter Decimal Value", value: if( a!isNullOrEmpty(local!testDecimal), null(), fixed(local!testDecimal, 2) ), saveInto: { a!save( local!testDecimal, if( a!isNotNullOrEmpty(save!value), todecimal(trunc(todecimal(save!value), 2)), todecimal(null()) ) ) } ) )
a!floatingPointField cannot restrict decimal input during typing because it lacks a decimalPlaces parameter and relies on native browser number input behavior.Try this
a!localVariables( local!dentalPremium: null, a!textField( label: "Dental Premium (Annual)", labelPosition: "ABOVE", refreshAfter: "UNFOCUS", value: if( a!isNullOrEmpty(local!dentalPremium), null, text(local!dentalPremium, "0.00") ), saveInto: a!save( local!dentalPremium, if( a!isNullOrEmpty(save!value), null, floor(todecimal(save!value) * 100) / 100 ) ) ) )
Thanks Shubham Aware and Mike Schmitt .. using this i was able to achieve 80% but if i gave alphabets its throws error and it breaks the screen. Instead of that how can we show validation message .
Oops - my null check in the saveInto should have done the null test against the "todecimal" version of the save!value just to make sure it contained anything valid after invalid characters are stripped out. Here's mine again but with that one function added back in, and it works even when junk, text-only, or mixed (number and text) info is entered.
a!localVariables( local!testDecimal: null(), a!textField( label: "Fake decimal entry", refreshAfter: "KEYPRESS", placeholder: "Enter Decimal Value", value: if( a!isNullOrEmpty(local!testDecimal), null(), fixed(local!testDecimal, 2) ), saveInto: { a!save( local!testDecimal, if( a!isNotNullOrEmpty(todecimal(save!value)), todecimal(trunc(todecimal(save!value), 2)), todecimal(null()) ) ) } ) )
a!localVariables( local!data, a!floatingPointField( label: "Dental Premium (Annual)", labelPosition: "ABOVE", value: local!data, saveInto: { a!save( local!data, if( a!isNotNullOrEmpty(todecimal(save!value)), (save!value), todecimal(null()) ) ), }, refreshAfter: "UNFOCUS", validations: { if( not( regexMatch("^[0-9]*\.[0-9]{2}$", local!data) ), "Please enter a valid number with up to 2 decimal places.", {} ) } ) )
Hi Mike Schmitt Shubham Aware . Thank you for the help, it works well. But here now user dont want to truc the values instead of that expecting to show the validation so that they will give what they want either they want rounded value or raw data.For that i tried using below regexMatch function for the validation, but the issue is it is throwing validations if we give round values (123)or 1 decimal values (12.10). Can you please help how to show validation only when they enter more then 2 decimal
Check this
a!localVariables( local!dentalPremium: null, { a!floatingPointField( label: "Dental Premium (Annual)", labelPosition: "ABOVE", value: local!dentalPremium, saveInto: a!save(local!dentalPremium, save!value), refreshAfter: "UNFOCUS", validations: if( and( a!isNotNullOrEmpty(local!dentalPremium), mod(local!dentalPremium * 100, 1) <> 0 ), "Please enter a value with up to 2 decimal places (e.g., 12, 12.1, or 12.67)", null ) ), a!textField( label: "Current Value (Debug)", value: local!dentalPremium, readOnly: true ) } )
Yes Shubham Aware it works Thanks. out of curiosity i have one question. if we go with validation we cant keep the 2 digit formatting right? means if user enters 12, we cannot show 12.00 or if 12.1 wont be able to show 12.10 . because then it will restrict user from typing more values right. please correct me if i am wrong.
Yes, you're correct. With validation, floatingPointField always strips trailing zeros (12 stays 12, not 12.00) because formatting with text(value, "0.00") converts to string and breaks number input.Validation = editable but no .00 display ; Formatting = shows .00 but not editable.
Thanks Shubham Aware for sharing the knowledge.