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.
1 Answer
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. Commented Mar 22, 2018 at 3:47