Old error shown when setFieldValue and setFieldTouched are executed together
See original GitHub issueAfter executing the following code, Formik shows an error based on the previous value. The order of the two lines doesn’t make a difference.
this.props.setFieldValue('rating', value);
this.props.setFieldTouched('rating', true);
Wrapping setFieldTouched
in setImmediate
solves the problem so I presume it’s some kind of race condition?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Issue with values Formik - Stack Overflow
When you call getValues , it gets old value as setFieldValue ... I had a simmilar problem connected to setFieldValue and setFieldTouched ....
Read more >formik onchange not working
GitHub Bug report Current Behavior Form not validating on change, ... After executing the following code, Formik shows an error based on the...
Read more >Build and manage form using Formik and Yup, in React Native
};const EditProfile = props => { return ( <Formik> {({ dirty, values, setFieldValue, errors, touched, setFieldTouched, isValid,
Read more >withFormik() | Formik
If specified, your wrapped form will show up as Formik(displayName) . ... reset props.errors to this initial value (and this function will be...
Read more >Build Your Own Formik Using React Hooks with Jared Palmer
onBlur should be used over onMouseDown so that errors aren't shown before the ... tells it to not run if the value hasn't...
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 FreeTop 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
Top GitHub Comments
I still have this issue:
I am changing the value from 2016-01 to 2020-02. The validation was called twice, with new and old value:
So, field was marked as valid, that is incorrect.
I was forced to WA:
No, this is in the browser. I’m using a custom StarRating component and the change is triggered by an onClick under the hood. I assume it would work properly with radio elements and their onChange, then On Mon, 31 Jul 2017 at 16:31 Jared Palmer notifications@github.com wrote: