Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Material-UI] [Date field] Change the date format from 'mm-dd-yyyy' to 'dd-mm-yyyy' #2425

Closed
3 tasks done
mimiski opened this issue Jun 13, 2021 · 4 comments
Closed
3 tasks done

Comments

@mimiski
Copy link

mimiski commented Jun 13, 2021

Prerequisites

Description

I'd like to change the date format from 'mm-dd-yyyy' to 'dd-mm-yyyy'. How to do that?

Steps to Reproduce

  1. Create a date field ({type: "string', format: "date"}).
  2. The field's format is 'mm-dd-yyyy'. How to change it to 'dd-mm-yyyy'?

A minimal example: https://jsfiddle.net/fLzewap2/9/

Best regards,
Kuba

@epicfaace
Copy link
Member

For the bootstrap theme, we just use a plain HTML5 input. This displays the date format based on the user's locale (so it can be dd-mm-yyyy for some locales, but mm-dd-yyyy for others). See https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format

If you want to force it to say "dd-mm-yyyy", your best bet is to create a custom widget that does this. There might also be other options in other themes that allow you to change the format, but I'm not sure exactly about if they exist.

@mimiski
Copy link
Author

mimiski commented Jun 13, 2021

@epicfaace Thanks for the quick response.
According to https://stackoverflow.com/questions/46543391/change-formatdate-in-datepicker-of-material-ui, in plain Material-UI you should use

<Field
      name="dateFrom"
      component={DatePicker}
      [...]
      formatDate={(date) => moment(date).format('DD-MM-YYYY')}
/>

Is there a way to pass on the formatDate={(date) => moment(date).format('DD-MM-YYYY')} argument in RJSF schema/UI schema without implementing a separate widget?

@epicfaace
Copy link
Member

That's not possible at the moment, though it will be possible after #1647 / #1672 are resolved / merged.

@mimiski
Copy link
Author

mimiski commented Jun 14, 2021

I see, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants