You need to sign in to do that
Don't have an account?
Leticia Monteiro Freitas 4
Data Masking in Lightning Component
Hello,
I need set a mask on my lightning input text, to get de Data Format. (YYYY-MM-DD)
Can anyone could help me?
I need set a mask on my lightning input text, to get de Data Format. (YYYY-MM-DD)
Can anyone could help me?
It seems it can't be done using lighting:input tag but it can be done using ui:input tag.
<ui:inputDate aura:id="EndDateField" value="" displayDatePicker="true" format="yyyy-mm-dd"/>
Thanks.
When i do this, i just see the format that i need use.
This will work when data needs to be saved in a date field later. For example:
<ui:inputDate aura:id="DOBFIeld" value="{!v.contactObj.Birthdate}" displayDatePicker="true" format="yyyy-MM-dd"/>
Here Birthdate is a date field on contact. Initially, it will show a date picker and when I select any date in date picker, it shows the date in given format. The data in the system will be saved as date and will be shown to the user based on its locale etc on the page layout.
I understand that you are trying to save this date in a text field and not on a date field. Even if I change the value attribute to a text field, it is working fine for me. For example:
<ui:inputDate aura:id="DOBFIeld" value="{!v.contactObj.AssistantName}" displayDatePicker="true" format="yyyy-MM-dd"/>
This is showing date picker to me, showing date in given format and when I save the values, AssistantName which is a text field is showing date in given format.
if you don't want to use datePicker here, and set displayDatePicker="false", the system will show the format as a placeholder but doesn't enforce the user to put values only in the given format. You will have to write custom logic in the JS controller for this ( which will be like grabbing the value, parse the string and put dashes in between). As the user can put any values in it, it's not a good idea to set displayDatePicker to false for date fields.
Thanks.