Formik: A lifecycle event called when validation fails after an attempted submit

Created on 18 Oct 2018  路  4Comments  路  Source: formium/formik

馃殌 Feature request

Current Behavior

Currently using withFormik, we have access to the handleSubmit method which will be called when the form is submitted and validation passes.

Desired Behavior

A method that is called when validation fails, for example, onValidationError. This can be used for an functionality you want to implement when the user tries to submit an invalid form.

Example: You may wish to scroll to an error message.

Suggested Solution

An onValidationError method that is called instead of handleSubmit if the validation fails.

Who does this impact? Who is this for?

This is for all users

Describe alternatives you've considered

Currently I am using the componentDidUpdate lifecycle method of my form element to check if a submission has taken place and now there are errors

componentDidUpdate = (prevProps) => {
// if form was submitting, but now is not submitting because it is invalid
if (prevProps.isSubmitting && !this.props.isSubmitting && !this.props.isValid) {
//scroll to top
window.scrollTo(0, 0);
}
}

Additional context

Duplicate

Most helpful comment

This will definitely be a nice functionality to have!

All 4 comments

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

I still think this would be a useful piece of functionality.

This will definitely be a nice functionality to have!

Duplicate #1484

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredpalmer picture jaredpalmer  路  3Comments

dearcodes picture dearcodes  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

pmonty picture pmonty  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments