How to restrict user to enter the decimal value in the UI field?

Hi Team,

I want to restrict user to enter only Integer value in the UI field. I created Number type UI field with 0 decimal places. But you can enter anything into the UI field.

I am storing that UI field value into the salesforce field which is also Number (18,0) type.

When user are enter decimal values then decimal values is saving into that field.

I also added the validation rule for restricting the field to enter the decimal values. But when validation error come then UI field is automatically showing the round off value on the UI but in the back end decimal value is present.

Can we done anything on the skuid side for this requirement.

Geeta Garg

The settings to control how many decimal paces are shown only control the UI.  They do not affect the database actions.  It could be argued that they should behave as “validation rules” on new data entry,  but that is not how we built them. 

I think you have two options. 

1. Remove the decimal place limit in Skuid and have the server side validation rule control the situation.  

2. Build some validation into the Skuid page that discovers when there are extra decimal places and prevents save.  

Here is a quick sketch of option 2: 
- Create a UI only formula field on the model where your number field is.  The formula should evalutate to true if there are decimal places.   (I’m going to let you do the formula…) 
- Conditionally enable the save button so it is only active if the formula field is not true. 
- Add a text block to your UI explaining the requirement - and only show that if the formula field is true. 

Hope that helps. 

I like Rob’s option 2. Preventing user to save and communicate with them about the validation issue is good practice in my opinion.

There is a third option. Some may call it hacky and may not like it, but… it’s an option. Using a model action whenever that field is updated to check whether the field has decimals and apply a ROUND() formula to the value. So it’s validating as you type.

Downside to this option is that if there is a decimal found in the input, you’ll lose the focus of the cursor on the input. But it won’t lose focus if there’s no decimals.

Here’s the xml for this experiment

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="false" showheader="false" showfooter="false">
<model id="NewModel" limit="20" query="true" createrowifnonefound="true" datasource="Ui-Only" processonclient="true">
<field id="integer-only" displaytype="DOUBLE" length="255" label="Integer Field" ogdisplaytype="TEXT" precision="9" scale="0"/>
<action type="updateRow" fieldmodel="NewModel" affectedrows="context">
<update valuesource="formula" field="integer-only" enclosevalueinquotes="false">
<basicfieldeditor showheader="true" showsavecancel="true" showerrorsinline="true" model="NewModel" uniqueid="sk-11LH-732" mode="edit">
<column width="70%" uniqueid="sk-11LH-728">
<section title="Section A" uniqueid="sk-11LH-729" collapsible="no">
<field uniqueid="sk-11LH-733" id="integer-only"/>
<field uniqueid="sk-11N2-820" type="COMBO" editmodebehavior="autopopup">
<template>Integer only. Number with decimals will automatically be rounded</template>
<column width="50%" uniqueid="sk-11LH-730">
<actionsequences uniqueid="sk-11LB-596"/>
<styleitem type="background" bgtype="none"/>