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.

Using Controller with React-Nice-Dates datepicker

See original GitHub issue

Describe the bug I’m trying to use a date picker for selecting a booking date, using a yup schema for validation.

After selecting a date using react-nice-dates date picker, the input value is not acknowledged and the field is marked as a validation error.

To Reproduce Steps to reproduce the behaviour:

  1. Go to this simplified CodeSandbox demo
  2. Click on the input to open the date picker,
  3. Select a date
  4. Attempt to submit the form
  5. See validation error message

Codesandbox link Simplified CodeSandbox demo

Expected behavior The selected date value should be correctly identified as a valid input and therefore pass schema validation.

Desktop

  • OS: MacOS
  • Browser: I’ve tried in both Chrome & Safari
  • Version: Chrome (80.0.03987.132) & Safari (12.1.1)

Additional context

  • I’ve included simplified versions of validation schema and date picker components I’m using
  • From what I can gather, the Controller onChange event is never called 🤷‍♂️

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
bluebill1049commented, Mar 16, 2020

no worries 😃 here you go: https://codesandbox.io/s/react-hook-form-and-react-nice-dates-wrapped-at-controller-qogy4

because the external component is not following standard onChange and value props.

have a read on the doc: https://react-hook-form.com/api#Controller where you can change the method and value name 😃

1reaction
bluebill1049commented, Mar 17, 2020

Oh man you are too kind! Thank you very much for your feedback. To be honest i am so glad this lib is working for you, you are definitely my target audience who is nice, kind and appreciative!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Hook Form and React Date picker - Wrapped at Controller
TemplateReact Hook Form and React Nice Dates - Wrapped at Controller; Environmentcreate-react-app. Files. public. src. App.js. index.js. schema.js.
Read more >
React custom datepicker: Step-by-step - LogRocket Blog
In this article, we'll solve the issue by building a custom React datepicker from scratch using native JavaScript Date objects.
Read more >
Is it possible to use react-datepicker with react hooks forms?
How can I implement "yup" required validation with the Controller(DatePicker)? I need to display the required field message when no date is ...
Read more >
React Nice Dates
React Nice Dates is composed of a set of components and utilities with different levels of abstraction that you can use to build...
Read more >
react-datepicker - npm
A simple and reusable datepicker component for React. Latest version: 4.8.0, last published: 7 months ago. Start using react-datepicker in ...
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