react-admin
react-admin copied to clipboard
DateInput with support for Locale selection or documentation to do it
Is your feature request related to a problem? Please describe. The format of the input DateInput is not the default for many countries (like Brazil, it would be DD/MM/YYY) and would be nice to use it in the correct format.
Describe the solution you'd like
That I use a prop to set the Locale (like in NumbersField) using Intl.DateTimeFormat. Like in NumbersField:
<DateInput source="date" locales="pt-BR" />
Describe alternatives you've considered
Use Intl.DateTimeFormat
If it is not possible, put in the documentation some way to change the format. Maybe the format/parse, but I don't know how to do it.
I thought abou use the https://github.com/vascofg/react-admin-date-inputs , but it is 3 years old, not changed for react-admin v4.
Their solution is like:
<DateInput source="date" label="Date in ptBR!" providerOptions={{ utils: DateFnsUtils, locale: ptBR}} />
Thanks for the report. I will discuss the topic with the team to define its implementation priority.
<DateInput> renders a native <input type="date">, the UI of which depends on the locale defined in the user browser. So the default date format should match the users's preferences. I don't understand why it's not the case for you.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
Besides, HTML doesn't offer any way to force date formatting on date inputs. To allow what you ask, we'd need to reimplement <input type="date"> completely. This is outside the scope of react-admin, so we won't address it.
Note that you can use third-party Date input libraries like MUI's DatePicker
https://mui.com/x/react-date-pickers/date-picker/
My Chrome have multiple languages, and it was sending en-US first... After change the order and the UI language, the input shows correct. Thanks and sorry to bother!!