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

How to skip validation for the field not exists in form using Formik + Yup? #2075

Open
harleenarora opened this issue Nov 28, 2019 · 3 comments
Labels

Comments

@harleenarora
Copy link

I want to add validation if a particular field exists in the form, otherwise, there should not be any validation or skip validation for that field.

How can I achieve this?

@spawluk
Copy link

spawluk commented Nov 29, 2019

use
object({}).test()

@kaldebert
Copy link

kaldebert commented Dec 2, 2019

You can also use when.
For example, add a required validation on foo if bar is present :

foo: mixed().when("bar", {
    is: value => !!value,
    then: mixed().required()
  }),

@stale stale bot added the stale label Jan 31, 2020
@luismasg
Copy link

luismasg commented Jun 25, 2021

so what i just did

<Formik
onSubmit={actualSubmitFunction}
. .

<button onClick={vales.valueExists? submitForm(): actualSubmitFunction(values)}>submit </button>

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

No branches or pull requests

4 participants