Question
Can not get errors in onSubmit callback
Get errors in onSubmit callback.
I want to display errors in a Dialog when user submit a form.
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
}
})
/>
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.
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', });