Formik: How to get `errors` in `onSubmit` callback?

Created on 9 Jan 2018  路  2Comments  路  Source: formium/formik

Bug, Feature, or Question?

Question

Current Behavior

Can not get errors in onSubmit callback

Desired Behavior

Get errors in onSubmit callback.

I want to display errors in a Dialog when user submit a form.

Suggested Solutions

Add a new onSubmitWithErrors prop, which does not break current implementation.

<Formik
   onSubmitWithErrors={(values, bag) => {
      if (bag.errors) {
         Toast.error(bag.errors)
     } else {
       // send values to server
    }
})
/>
Question

Most helpful comment

here's how i'm doing it
``javascript const loginUser = withFormik({ handleSubmit: async (payload, {props, setSubmitting, setErrors}) => { try { const errors = await props.handleSubmit(payload); setSubmitting(false); setErrors(errors); } catch (e) { throw (e); } }, displayName: 'LoginForm', });

All 2 comments

here's how i'm doing it
``javascript const loginUser = withFormik({ handleSubmit: async (payload, {props, setSubmitting, setErrors}) => { try { const errors = await props.handleSubmit(payload); setSubmitting(false); setErrors(errors); } catch (e) { throw (e); } }, displayName: 'LoginForm', });

This is not possible right now. handleSubmit does not get executed if there are any errors present.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jordantrainor picture jordantrainor  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments

green-pickle picture green-pickle  路  3Comments

najisawas picture najisawas  路  3Comments

dfee picture dfee  路  3Comments