react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

DateInput decrease the day by 1 when you change its value and trigger a form validation function

Open gabe-o-fetchly opened this issue 1 year ago • 15 comments

What you were expecting: DateInput to always have the value sent to the validation function exactly as it displays on the component

What happened instead: see below

Steps to reproduce: The DateInput day value decrease by 1 when you log its value on a validation function, but only if you change the date initial value, for example if the initial value is today, when the issue happens, the day of the date is decreased by 1... How to reproduce:

  • Add a validation prop to your form like so: validate={validateCreate}
  • Set the forms validation modes to submit: mode='onSubmit' reValidateMode='onSubmit'
  • Insert a default value on the DateInput, as a prop like this: defaultValue={new Date().toISOString().split('T')[0]}
  • Add a simple log to the validation form value for the DateInput (my DateInput source is called start_date): console.log(values.start_date)
  • Open the page where you have your DateInput and press the save button
  • You will see that the date is correct, since it has the initial value
  • Change your Date to something else and press Save again, you will see the date has decreased by 1 day, and if you keep testing, you can see that it only happens if you change the date to something else other than the initial value

Related code: Dont have a codesandbox, its very easy to reproduce this

Environment

  • React-admin version: from package-lock: "node_modules/react-admin": { "version": "5.1.3", ... }
  • Last version that did not exhibit the issue (if applicable):
  • React version:
  • Browser:
  • Stack trace (in case of a JS error):

I would love to get some idea how to work around this issue

gabe-o-fetchly avatar Sep 12 '24 00:09 gabe-o-fetchly