question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

date field validation bug

See original GitHub issue

Describe the bug When yup.date() field gets empty string for validation, it throws error even if field is nullable or not required.

ValidationError: required must be a date type, got: “Invalid Date” instead

To Reproduce https://runkit.com/michal-de/yup-date-bug

Expected behavior Empty string case should be considered as null or undefined.

Platform (please complete the following information):

  • Browser: chrome
  • Version: 79.0.3945.130 (Official Build) (64-bit)]

Additional context Empty string is default html input value for type date or datetime-local.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:9
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

94reactions
lucasconstantinocommented, Oct 24, 2020

Fixed with nullable and transform, to avoid polluting the input/html code:

const schema = Yup.date()
  .nullable()
  .transform((curr, orig) => orig === '' ? null : curr)
  .required('Mandatory field message')
47reactions
rexebincommented, Mar 7, 2021

@4ortytwo you can customize the error message via typeError.

yearEndDate: date().nullable().typeError('Invalid Date') works like dream.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date field keeps giving validation error even though submitted ...
I'm having a strange problem with a date field on a webform. I have it set, in the Element Settings, to a minimum...
Read more >
Date Valid Bug? | OutSystems
You will have to validate for example if the field is a Date and if the variable is not empty. And so you...
Read more >
"Date" Field Validation Error - Laracasts
i have two question. I put data in both field "Department Name" and "Starting Date" but validation message occur that "The depjdate field...
Read more >
Why am I getting a Date/Time Validation error when entering ...
Why am I getting a Date/Time Validation error when entering data in Quality Window? · A bad Date/Time was entered manually · The...
Read more >
date field failed validation error - General Product Use
Even when using the date field drop-down calendar to fill in the date I am getting the error message "date field failed validation....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found