Can't call setTouched and setError
See original GitHub issueAfter submitting a form and getting async error responses I want them to be visible on the form.
My inputs show an error when form.errors[field.name] && form.touched[field.name];
So I try to both set errors and touch the related fields.
So far I’ve tried:
setErrors(errors)
setTouched(touched)
as well as looping through all errors and calling
setFieldError(key, name)
setFieldTouched(key, true);
In either case, whatever I call second works and the first doesn’t. it looks like setErrors overwrites touched and vice versa.
I also tried setStatus({ errors, touched })
, but that didn’t seem to work at all, but maybe I’m using the API wrong here.
- Formik Version: 0.10.5
- OS: macOS
- Node Version: 9.3.0
- Package Manager and version: npm 5.6.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to properly use Formik's setError method? (React library)
The api error message will show until the next validation call by Formik (i.e. the user is fixing something). But the status message...
Read more >API Reference - Formik
A top-level status object that you can use to represent form state that can't otherwise be expressed/stored with other methods. This is useful...
Read more >useForm - setValue - React Hook Form
This function allows you to dynamically set the value of a registered field and have the options to validate and update the form...
Read more >useField - VeeValidate
The field name, this is a static string and cannot be changed. ... a the errors to a single error message setErrors('field is...
Read more >solid-js-form - npm
Api Reference. useField; setValue; setError; setValues; setErrors; setTouched; handleChange; handleBlur; formHandler ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
See latest version of formik
setFieldTouched
will rerun your validations, unless you’ve set validateOnBlur tofalse
…which are overwriting your call tosetFieldError
.Now that you can call
validate
, I am going to add a third argument to all the setters that lets you prevent calling validation. This will further prevent confusion.