5

i have a markup like below when i enter numbers in the field like 12345 it comes as '12,345'. I dont want commas in the number field. the fields functional significance is that its a zipcode field. so it doesnt look good to my client if they see commas in a zipcode field.

Any help would be appreciated.

4

I would not use lightning:input with type="Number" for zipcode instead will prefer using default with type="text" and use pattern to validate the right format

Here is a sample code

<lightning:input pattern="[0-9]{5}" name="number" label="Number" value="12345"/>

The above automatically validates that user uses 5 digit zipcode else it throws an error .

If you are looking for internationalization solution then the below link lists all the patterns

  • The field type is number in the backend salesforce object. So this means should i convert string to number before i save the data in salesforce? – RedDevil Apr 15 '17 at 17:26
  • I would keep the backend field to be of string datatype as well and write a validation rule to maintain data integrity .The number field helps in aggregation or any sort of numeric calculation while you do not want to do any numeric calculation on zipcode .So to me Zipcode should be a text field both at front and backend . – Mohith Shrivastava Apr 15 '17 at 17:30
  • 1
    @RedDevil - Standard PostalCode fields are test fields not numbers – Eric Apr 15 '17 at 17:31
  • Thank you so much Mohith and Eric for taking time to reply. Maybe i gave a bad example. what if i want to use lightning input type = number without commas. Is that even possible? – RedDevil Apr 15 '17 at 17:48
  • That's a great question .I will see if I get any hint on how to do this .Let's keep the question open – Mohith Shrivastava Apr 15 '17 at 17:49
1

Personally, I would hate to use hacky ways to work around limitations of Salesforce, but since there seems to be no easy way to fix this using the formatter options Salesforce provides for lightning:input, here's some CSS as a quick fix:

input.slds-input {
    opacity: 1 !important;
}

The !important is important since there's no other way to override inline styling applied by Salesforce's Aura framework.

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.