jaredpalmer / formik

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

test validationSchema without message not working #2217

Open alextrastero opened 4 years ago

alextrastero commented 4 years ago

📖 Documentation

Sorry if the format is wrong, I just wanted to write my findings regarding the validationSchema prop.

I have an IBAN form input where I wanted to add a custom validation (aka test).

const schema = object({
  iban: string().test('name', '', () => false), // no message
})

<Formik validationSchema={schema} ...

In this example the form will submit ignoring the iban test.

I'm not sure this is a bug in yup, as using schema.isValid works fine.

alextrastero commented 4 years ago

Thanks for the great library btw

SamKirkland commented 4 years ago

The second param to the .test() method is the error message. This param must be a non-falsy value (ex: "", 0, false) You can fix this issue by passing in a string as the second param

const schema = object({
  iban: string().test('name', 'something is wrong with name...', () => false), // no message
})

<Formik validationSchema={schema} ...