Formik: validate: async() => is not working

Created on 25 Mar 2019  路  4Comments  路  Source: formium/formik

馃悰 Bug report

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

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)

stale

Most helpful comment

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.

All 4 comments

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={() => {}}
    >

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

Errors correctly appear in props.

Is there an issue reported about this?

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

giulioambrogi picture giulioambrogi  路  3Comments

najisawas picture najisawas  路  3Comments

outaTiME picture outaTiME  路  3Comments

ancashoria picture ancashoria  路  3Comments

najisawas picture najisawas  路  3Comments