3

I am using <lightning:recordEditForm> and <lightning:inputField fieldName="customField"/> to create a form. My custom field is Number field with setup number(16,2) - length 16, decimal places 2.

When i try to insert decimal number to my form, i get the error message:

enter image description here

Anybody faced the problem?

Thanks in andvance.

  • What locale is related to your current user? – Martin Lezer May 15 '18 at 8:22
  • What you mean by locale? I am testing this as system administrator. Also if i create a same field on lets say Account object, which has standard form for creating a record, then the decimal number works. Problem is, that on my custom object, i am using lightning component to override my record createion form. And i use lightning:inputField to display all fields i want. Everything work fine - date, test, lookup etc. But number fields are not in right configuration ( not allowing decimals ). – RSICK May 15 '18 at 8:26
  • One more thing- it displays error and rounds number to full integer, e.g if i write 15.59 its shows 16 when not onfocus, But allows to save record and on detail page the number is decimal. – RSICK May 15 '18 at 8:36
  • could you try with a comma instead of a period? – Koen Certyn May 15 '18 at 13:38
4

The issue seems in the way lightning:inputField has been implemented. Here are some interesting findings around lightning:inputField implementation.

And I posted an idea based on this issue on the idea forum for this.


Once rendered, lightning:inputField with underlying field as Decimal is rendered as HTML <input type="number" ../>. This HTML tag has a step attribute which determines the decimal increment value for the input being entered in the field. If you observe the step value for a rendered inputField component on Chrome console, it shows as step="1" with all other details.

Interestingly, there's no step attribute available for lightning:inputField, thus you really cannot control this value and its up to the framework to define that, which looks like it's only defaulted as 1 in this case.

My code as on component:
<lightning:inputField aura:id="customField" fieldName="jdforce__My_Decimal_Field__c"  />

As rendered:  
<input type="number" id="input-1" step="1" name="jdforce__My_Decimal_Field__c" class="slds-input" style="position: absolute; opacity: 1;">

And if you edit the generated HTML to change the step value in there, you will see that you don't get the error.


Now, if you use lightning:input which is derived from HTML input tag, you have an option of setting the step value for this component. So if I have something as below in my component, I can control what are the allowable values.

My code as on component:
<lightning:input type="number" name="decimal" label="Enter a decimal value" step="0.01"/>

As rendered:
<input type="number" id="6:0" step="0.01" name="decimal" class="slds-input" style="position:absolute;" data-aura-rendered-by="15:0" >

Now in this scenario, if I attempt to say enter a value of 15.591, I get the same error (Your entry isn't a valid increment) because my step is defined to allow only two decimal places in this case.


Your Option:

To mitigate this scenario, you may just like to utilize lightning:input for decimal fields only in conjunction with lightning:inputField for other fields and during the component initialization, fetch the value from underlying record for all decimal fields and set the values in there.

  • Thank you for the reply. I inspected the dev console too and noticed that the step is 1 and lightning:inputFieldis not offering us any flexibility on that. Currently i am trying to use lighning:input and add new field to the recordEditForm component with value from lighning:input field before i submit the form. Not sure if i can add fields to recordEditForm in onsubmit() function. Anyways thanks again for helping :) – RSICK May 16 '18 at 7:39
  • Lightning:input is beta so keep your client team informed of that. In summer 2018 lightning input has had lot of issues – RedDevil May 16 '18 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.