1

The lightning input field has an attribute "pattern". What pattern should i use? I've already tried "mm/dd/yyyy" but it doesn't work.

3

The pattern attribute is for a Regex validation:

Specifies the regular expression that the input's value is checked against

the component does not support this,

An interesting post for you to read to better understand the reasoning behind this would be Is there any way to change input type=“date” format?. Bascially, it comes down to web standards.

One way to do this would be to create your own text input component and set a placeholder:

<input type="text" name="input" placeholder="dd/mm/yyyy" pattern="[0-9]{2}-[0-9]{2}-[0-9]{4}" title="dd/mm/yyyy"/>

and combine with the SLDS component for date picking

Unfortunatelly, to my knowledge, you have to create it from scratch. Maybe someone else can share a more viable solution.

  • hmmm sounds doable. I'll tinker with this and let you know. Thanks a lot. – SamuelDev Mar 22 '18 at 3:47

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.