formik
formik copied to clipboard
When submitting, touched object is not created with the right shape and values
Bug report
Current Behavior
When using similar field components in a nested form object, the touched object is not created accurately at pre-submit phase. Pressing submit does not show the validation errors on the fields.
Expected behavior
When pressing the submit button the touched object should be created accurately and the form should show the validation errors.
Reproducible example
https://codesandbox.io/s/formik-codesandbox-template-forked-h2fxvk?file=/CustomTextField.jsx
Additional context
Seems related to the setNestedObjectValues
method and the way it uses the value objects as keys in the WeakMap.
Your environment
Software | Version(s) |
---|---|
Formik | 2.2.6 |
React | 16.13.1 |
TypeScript | 3.8.3 |
Browser | Chrome Version 101.0.4951.54 (Official Build) (64-bit) |
npm/Yarn | Yarn 1.22.18 |
Operating System | Ubuntu 20.04 |
Got the similar error in Next.js based on Formik.
TypeError: Cannot read property 'touched' of undefined
at t.n.render (/app/node_modules/formik/dist/formik.cjs.production.min.js:1:17956)
I don't get any errors, the touched object is not created properly.
@Dandrum did you get it sorted? seeing the same issue on nextjs but on production build only
@Dandrum did you get it sorted? seeing the same issue on nextjs but on production build only
Well i removed the Formik ErrorMessage component and implementet the small part by myself like in the docs.
{error && (
<Alert
variant=''
className={
'fade bg-danger text-white alert alert-dismissible show'
}
>
{error.message}
</Alert>
)}
- Alert in this case is a bootstrap component ;)
Yea the error component seems to be causing this issue. Interestingly enough it started happening with the latest nextjs update so not sure if its a formik issue or nextjs
I am not using nextjs, which leads me to believe it is a formik issue.
This issue resolved itself for me in a recent renovate minor patch upgrade so I suggest trying the latest version.