formik: Setting no validate or validationSchema clears out imperative error state on onBlur/onChange
Current Behavior
Whenever you setup a Formik form and supply no validate or validationSchema, but you call setErrors/setFieldError as if it’s coming from an API, it will clear out the entire errors object from Formik whenever you change or blur ANY field.

Steps to Reproduce
See codesandbox for more info
Expected behavior
I would say whenever you apply no validate or validationSchema, it should only clear out the error of the field you touched, not the entire form.
Suggested solution(s)
I guess onBlur and onChange validation should only clear out the field it is actually touching/changing.
Additional context
Note: The Formik version of 0.11.11 does not clear the errors object on change or blur at all (which to me seems a bit more reasonable, since you explicitly set the errors yourself and there’s not validation, so you’ll have to manually clear them as well).
Note: I haven’t tested if this behaviour also happens whenever you do have a validate or validationSchema setup.
CodeSandbox Link: https://codesandbox.io/s/pykpn4386m
- Formik Version: 1.0.3
- React Version: 16.3.2
- TypeScript Version: -
- Browser and Version: Chrome Version 68.0.3440.106 (Official Build) (64-bit)
- OS: OS X 10.13.6
- Node Version: -
- Package Manager and Version: -
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 16
- Comments: 31
I don’t think this is stale. I am curious if this behaviour is intended or whether it’s a bug 🤔
So, for someone still finding this thread, you can just set
validateOnBlur={false}andvalidateOnChange={false}on yourFormikcomponentI get a similar issue when I try to
setFieldErrorwhich I haven’t invalidationSchema. So I can get this error, but when I’m editing another field, an errors object contains all of the errors except error fromsetFieldErrorI guess this issue because
Here prevState.errors and errors are different, and if they are different we return new errors object… Maybe I’m incorrect here…
@jaredpalmer , could you please help us here?
I am experiencing the same problem and setting the third parameter “shouldValidate” on either setFieldTouched or setFieldError has not impact.
The setFieldError places the error in the error collection; however, it is removed again before the final re-rendering.
Anyone managed to solve this?
Hi @inooid Thanks for posting this issue, I’ve debug this and found an appropriate solution to fix this issue. You can use setStatus to manage the BE errors.
So Here we can use setStatus instead of setFiedError.
@CalvinD3v honestly can’t remember what I did to solve this. There are some ideas listed above though 👍
@ImSolitude @val-samonte TBH I don’t really think anybody gonna handle this, because this was reproducible in early 1.0.3 Formik version, which was in alfa at that time.
And if I’m not mistaken it was fixed in 1.1 or some newer versions. So if you still use Formik 1.0.3 or similar alfa version maybe you should try to update it or if you still face this issue in newer versions of Formik maybe it will be more appropriate to open a new issue.
I think this needs to be reopened.