question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't call setTouched and setError

See original GitHub issue

After 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
jaredpalmercommented, Feb 11, 2018

See latest version of formik

1reaction
jaredpalmercommented, Feb 7, 2018

setFieldTouched will rerun your validations, unless you’ve set validateOnBlur to false…which are overwriting your call to setFieldError.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found