-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Validation not working properly with setFieldError inside onBlur in 2.2.9 #3275
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hello @slutske22 , that's the only solution I founded: `` const initialValues = { const validationSchema = Yup.object().shape({ export default function App() { return ( {(formikProps) => ( <> Name <TextField error={formikProps.errors.name} fullWidth helperText={ formikProps.touched.name ? formikProps.errors.name : "" } name={"name"} onChange={formikProps.handleChange} onBlur={(e) => { if ( existingNames.includes(e.target.value) && formikProps.values.nameref !== e.target.value ) { setCustomError(true); // formikProps.setFieldError( // "name", // "Another template already has this name" // ); } formikProps.handleBlur(e); }} value={formikProps.values.name} /> {customError && ( <div style={{ color: "red", fontSize: "10px" }}> Another template already has this name )} </> )} ); }`` |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 60 days |
I am seeing this after an upgrade from 2.2.6 to 2.2.9 as well, my guess is its the PR in 2.2.7 as 8 and 9 are types and lodash upgrades. |
Also having the same issue but not using When I log all the errors I think this conditional was actually hiding another bug. What I see happening:
Which seems outdated info. But because both are the same it wasn't dispatched in version @artola @jaredpalmer would this be enough info (together with the reproduction in the issue description) ? Anything else I can do to get this issue fixed? |
facing same issue |
Bug report
Current Behavior
When trying to set an error manually using
formikProps.setFieldError
, from within the blur handler of a form input, validation is not ocurring as expected. Take this simple example:In this example, I would expect that when the field blurs, if
existingNames
includes the value of input, the error should be created and show an error message. Note that this does indeed work in v2.2.6, as can be seen in this codesandbox. However, this is not working in 2.2.9Expected behavior
I would expect that when you manually
setFieldError
inside a blur handler, that error should register with FormikReproducible example
Example of how this is broken in 2.2.9
Example if how it should work, as in 2.2.6
In either example, type in one of the existing names in the list of
existingNames
, 'name1' or 'name2'.Suggested solution(s)
Frankly I'm not sure how to fix this, but it seems to be related to #3199. I've tried every variation of
validateOnMount
,validateOnBlur
, andvalidateOnChange
, nothing seems to help.Your environment
The text was updated successfully, but these errors were encountered: