Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manually calling formik.submitForm() resolves with undefined #2057

Open
Wgil opened this issue Nov 22, 2019 · 13 comments
Open

Manually calling formik.submitForm() resolves with undefined #2057

Wgil opened this issue Nov 22, 2019 · 13 comments

Comments

@Wgil
Copy link

Wgil commented Nov 22, 2019

馃殌 Feature request

Current Behavior

Calling formik.submitForm() promise manually, resolves always with undefined regardless of what my handler returns.

Desired Behavior

I'd like this to be resolved with the return value of my submit handler so I can decide what to do next.

https://codesandbox.io/s/inspiring-fog-9pmo8

@alexlurvey
Copy link

The issue I just had with this function was the promise not being rejected when the form is invalid.

The docs say this: The promise will be rejected if form is invalid.

I'm trying to figure out how to take action after an invalid submit without watching all the Formik state flags changing.

@DamodarSojka
Copy link

Also run into that, for anyone looking for a temp workaround:
use validateForm to check if there are any errors

@jaredpalmer
Copy link
Owner

Fixed in 2.1

@chornos13
Copy link

I still experienced with the issues I don't know what is wrong

@shakibmiraki
Copy link

I experienced the issues too
the version i'am using is 2.1.4

@druvisc
Copy link

druvisc commented Jun 20, 2020

Also getting undefined on 2.1.4.

@gastonmorixe
Copy link

Same, since combinedErrors is not an Error it doesn't throw.

@maddhruv
Copy link
Collaborator

re-opening as one more issue is reported - #2831

@maddhruv maddhruv reopened this Oct 22, 2020
@Macilias
Copy link

there is still no solution for that =0_0=

@dilshankelsen9y
Copy link

Running into this issue as well

@trungdeveloper
Copy link

Is there a workaround?

@Uvir127
Copy link

Uvir127 commented Jan 26, 2023

Has a workaround or fix been found for this?

@HammadRafiq
Copy link

I faced the same problem and got it fixed with my own workaround. I am validating and submitting the form on a manual click:
onClick={() => {
formRef.current.submitForm()
formRef.current.validateForm()
.then(values => {
if (Object.keys(values).length === 0) {
onSubmit(formRef.current.values)
}
})
}}
onSubmit() is the function that I only want to call if every value in my form is valid. formRef.current.submitForm() displays the errors (if there are any). The if condition inside formRef.current.validateForm() will only be true if there are no errors in the form.

In a nutshell:

  1. If some field is invalid in the form, show the error and dont call the onSubmit() function
  2. If all the data in the form is valid, call the onSubmit() function

formRef.current.values gives me all the values of form. If you are not aware, read it here on how to access Formik properties using useRef:
https://stackoverflow.com/questions/73233138/how-to-submit-formik-when-button-submit-outside-tag-formik-in-reactjs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests