jaredpalmer / formik

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

validate: async() => is not working #1392

Open fnpen opened 5 years ago

fnpen commented 5 years ago

🐛 Bug report

<Formik validate={async() => {
      return {
        name: 'Not valid'
      }
    }} onSubmit={() => {}}>

<Formik validate={async() => {}} /> is not working. I'm using it for server validation.

Current Behavior

"errors": {}

Expected behavior

"errors": {
    "name": "Not valid"
  },

Reproducible example

https://codesandbox.io/s/1oo6z653v7

Suggested solution(s)

fnpen commented 5 years ago

I found an example. I need to throw exception:throw errors;

<Formik
      initialValues={{ name: '' }}
      validate={async () => {
        const errors = {
          name: 'Not valid'
        };

        throw errors; // OK
      }}
      onSubmit={() => {}}
    >
tonyseing commented 5 years ago

This seems to be working now. I just tried to reproduce the error in codesandbox: image

Errors correctly appear in props.

ytimocin commented 4 years ago

Is there an issue reported about this?

michaeljohansen commented 4 years ago

For future travellers: Formik pre-2.0 used throw errors, v2.0+ uses return errors.

Source: https://github.com/jaredpalmer/formik/releases/tag/v2.0.1-rc.5

This issue can probably be closed.