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

use datepicker in formik #76

Closed
zahraHaghi opened this issue Dec 8, 2019 · 4 comments
Closed

use datepicker in formik #76

zahraHaghi opened this issue Dec 8, 2019 · 4 comments
Labels
question Further information is requested

Comments

@zahraHaghi
Copy link

zahraHaghi commented Dec 8, 2019

how can I use datepicker in formik?
I used it like this but when I submit form "required" error show
```

<Formik
         initialValues={{title: '', company: '', current: '', location: '', description: '', from: '', to: ''}}
         validationSchema={Yup.object({
             title: Yup.string()
                 .required('Required'),
             company: Yup.string()
                 .required('Required'),
             current: Yup.string()
                 .required('Required'),
             location: Yup.string()
                 .required('Required'),
             description: Yup.string()
                 .required('Required'),
             from: Yup.string()
                 .required('Required'),
         })}
         onSubmit={(values) => {
             console.log(values)
             props.onSubmitExp(values)
         }}
     >
         <Form className="mt-30 mb-30">
             <label htmlFor="title">Title</label>
             <Field name="title" type="text"/>
             <ErrorMessage className="error-message" name="title"/>
             <label htmlFor="company">Company</label>
             <Field name="company" type="text"/>
             <ErrorMessage className="error-message" name="company"/>
             <label htmlFor="location">Location</label>
             <Field name="location" type="text"/>
             <ErrorMessage className="error-message" name="location"/>
             <label htmlFor="from">From</label>
             <DatePicker
                 name="from"
                 value={selectedFrom}
                 onChange={setSelectedFrom}
                 inputPlaceholder="Select a day"
                 shouldHighlightWeekends
             />
             <ErrorMessage className="error-message" name="from"/>
             <label htmlFor="to">To</label>
          
             <DatePicker
                 value={selectedTo}
                 onChange={setSelectedTo}
                 inputPlaceholder="Select a day"
                 shouldHighlightWeekends
             />
             <ErrorMessage className="error-message" name="to"/>
             <label htmlFor="current">Current</label>
             <Field name="current" type="text"/>
             <ErrorMessage className="error-message" name="current"/>
             <label htmlFor="description">Description</label>
             <Field name="description" type="text"/>
             <ErrorMessage className="error-message" name="description"/>

             <button className="submit-btn" type="submit">Submit</button>
         </Form>
     </Formik>
@the-dr-lazy
Copy link
Contributor

the-dr-lazy commented Dec 8, 2019

To use the DatePicker or Calendar components with Formik you need to create an adapter component that uses Formik context. You can follow this CodeSandBox for inspiration.

@Kiarash-Z Kiarash-Z added the question Further information is requested label Dec 8, 2019
@zahraHaghi
Copy link
Author

To use the DatePicker or Calendar components with Formik you need to create an adapter component that uses Formik context. You can follow this CodeSandBox for inspiration.

so thankssss. It is worked for me

@Kiarash-Z
Copy link
Owner

@zahraHaghi We're glad your issue has been resolved. I'm gonna close this issue now

@nishant-k1
Copy link

To use the DatePicker or Calendar components with Formik you need to create an adapter component that uses Formik context. You can follow this CodeSandBox for inspiration.

Thank you so much!!

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

No branches or pull requests

4 participants