jaredpalmer / formik

Build forms in React, without the tears 😭
https://formik.org
Apache License 2.0
33.98k stars 2.79k forks source link

validationSchema prop for Field #2878

Closed enagy27 closed 3 years ago

enagy27 commented 4 years ago

🚀 Feature request

Add the ability to use validationSchema as a prop for <Field /> and useField(). This would make some forms of conditional validation easier, such as when a piece of a form is visible only if a previous option was selected. This ties validations to currently rendered content, which can be helpful sometimes.

Current Behavior

At the field level I'm able to add a custom validationSchema through the validate callback, but I'm curious if this should be baked into formik 🤔

Desired Behavior

<TextField
  required
  validationSchema={Yup.string()
    .required('Email is required')
    .email('Invalid email address')}
  name="email"
  type="email"
  label="Email"
/>
johnrom commented 4 years ago

I do not think this should be baked into Formik. I do however, think it would be great to move Formik.validationSchema to a package like formik-yup, and that package could create a custom <YupField which binds this functionality to Formik's Field.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days