-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
getFieldMeta does not return errors of nested field objects via yup schema #2956
Comments
We have the same issue after YUP update. With the following YUP schema, errors coming from object().shape({
'additionalInfo.referenceText': object().shape({
value: string()
.required(Translation.t('form.validation.referenceTextRequired'))
.max(30, Translation.t('form.validation.referenceTextTooLong', { length: 30 })),
}),
}); const { errors } = useFormikContext();
console.log(errors);
// {
// additionalInfo.referenceText: "Reference text is required"
// } Before YUP update, it's structure was as follows: {
"additionalInfo": {
"referenceText": "Reference text is required"
}
} And we had no problem retrieving individual form field error via const { error } = getFieldMeta('additionalInfo.referenceText');
console.log(error);
// Reference text is required |
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 |
Maybe this is because of YUP latest update? |
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 |
This is still an issue with yup 0.32.9. Actually, it's still broken for me in 0.27.0. Are you sure this is caused by yup? |
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 |
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 |
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 |
Did anyone have a solution? I'm having the exact same problem in a project 🥲 |
Yes found same issue here |
Definitely not a Yup issue. I am using |
Bug report
Current Behavior
After an update of Yup from 0.27.0 -> 0.29.3, yup introduced the following change jquense/yup#539 and this probably caused the following use case:
Given we have a yup schema validation with a nested object with a set of validation, the useFormikContext returns the form errors as a flat object previously set by yup schema.
this flat error structure causes that now the getFieldMeta does not return any nested object, array errors since it expects that the errors are nested.
The following function fails to return the nested error:
https://github.com/formium/formik/blob/83c0299a7e287e16e1b2ee2c5d54328f6f2fc7c3/packages/formik/src/Formik.tsx#L900
because the getIn function only loops for nested errors.
https://github.com/formium/formik/blob/83c0299a7e287e16e1b2ee2c5d54328f6f2fc7c3/packages/formik/src/utils.ts#L77
Expected behavior
getFieldMeta returns the nested field object/array errors defined via yup validation schema.
Reproducible example
Suggested solution(s)
Update getIn function to return also errors via nested keys.
Additional context
Your environment
The text was updated successfully, but these errors were encountered: