-
-
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
[Next] Nested FieldArrays and setTouched not working together #378
Comments
To add onto this: values.array is showing as an array, while touched.array is showing as an object. Both should have the same structure.
This comes straight from props.values and props.touched
|
Damn wish I knew about bury earlier. Will have to check this out more detail |
why not stick with lodash and use set which works for bracket notation AND dot notation... |
i believe this is a result of using dot notation to access array items. i am using bracket notation, and the array field gets completely replaced with a boolean. |
awww, what was wrong with my PR? =X |
Awww I'm sorry man. I was on a grind and just missed this. Agh. |
* Close #200. Add Field level validation * Regenerate doctoc * Remove handleChangeValue completely * v0.11.0-alpha.1 * Add missing name in call to setFieldError (#290) * v0.11.0-alpha.2 * #281 Add array helpers MVP, update ts setup for better DX (#298) * v0.11.0-alpha.3 * Actually export FieldArray * v0.11.0-alpha.4 * Upgrade to React 16, TypeScript 2.6.2 (#300) * #283 Update to React 16, TypeScript 2.6.2 * Update Travis build to use npm instead of yarn * Move back to yarn (#301) * Fix travis script to use yarn. * Add form to TS types of FieldArray * v0.11.0-beta.1 * Close #281 #155. Add docs about array helpers * Add field array examples and update toc * Fix unshift in FieldArray (#337) * Fix FieldArray component prop (#341) * Fix FieldArray component prop * nit: test names [skip ci] * Allow bracket path support (#334) * feat(Field): Allow bracket path support * chore(deps): Add types for lodash.topath * chore(deps): yarn.lock * Fix #280. Fix the definition dirty and isValid (#365) * Fix #280. Change the meaning of dirty and isValid * Lock in to path dep * Update tests for new definition of dirty * Update docs * Fixed typo in FieldArray code (#380) * Fix setDeep mutations with nested values (#373) * Fix start task * Get rid of mutators file * v0.11.0-rc.1 * #285 #122 Add example multistep / form wizard * #378 remove setFieldTouched from FieldArray * v0.11.0-rc.2 * #223 Fix checkbox validation error (again) * Add onReset callback. (#328) * feat(formik): Add onReset callback. * feat(formik): Use promise sniffing for onReset prop. This passes returned promise data to resetForm, allowing the promise to add new nextValues.
@jaredpalmer Hi, thank you for new component I noticed that
There are two elements in
You will see that new item has an error due to @jaredpalmer Is there any way to avoid this? Thanks in advance. |
Working on a fix now. |
I can't wait to merge my form branch into master!! |
I figured it out! Will open a PR |
@jaredpalmer I still get the error, when I leave the text box. Do I have to do something in code to dodge this error: formik.es6.js:5556 Uncaught TypeError: Cannot create property '0' on boolean 'true' Here is a code snippet:
It happens in the Field Component |
@eferrervaughn any update? this issue is still occurring |
It's good for me feel free to close |
@eferrervaughn no, what i meant is that this is also happening in my code, did you solve it? :p |
I'm also running into this error. Any updates? Should this issue be reopened? |
Running into this as well on v1 and v2 and I'm noting using a |
Not sure how to handle this situation tbh, maybe just encourage using |
For those looking for a solution I was doing something like: // base on some condition I either
setFieldValue('text', '');
// or
setFieldValue('text', { default: '', keys: [] }); I was changing the shape of a field value which was causing the The solution is to use resetForm(prevValues => ({ ...prevValues, text: '' });
// or
resetForm(prevValues => ({ ...prevValues, text: { default: '', keys: [] } }); |
@slightlytyler yes. Formik assumes that you keep you shape identical with respect to the path names. So in a nested situation if you go from a array to a value touched behavior could be off. you should indeed reset the form. |
I don’t think this is a bug, but it is a contract that we should document more explicitly. |
I was getting this error as well when using a custom slider input with setFieldValue and then typing and click out of a seperate empty Field or FastField component. Seems like the touched values were definitely off between array and value. I fixed the issue and eliminated the error on my end by using a custom input component instead of Formik's Field or FastField components alongside my custom slider. Old Input:
New Input:
|
@elvisguillen So is your structure an array of array items? Trying to understand why you put @jaredpalmer Is the documentation updated? Trying to find out how touched is being handled for an array of objects. |
Bug, Feature, or Question?
Bug
Current Behavior
When you have nested
FieldArrays
, let's say the following path:questions.0.values.0.label
wherequestions
andvalues
are the arrays andlabel
is a regular input field. WhenonBlur
is invoked on label, it wants to touch the path. But at that point (due to changing thevalues
array) the current touched state is:which causes the following error in
setDeep
:which happens on the last line of this method:
https://github.com/jaredpalmer/formik/blob/next/src/utils.ts#L69
Desired Behavior
It should update the touched state to a deep nested state like this:
Suggested Solutions
I'm not sure I understand the current implementation of
setDeep
. Why not just clone the object and use something like https://github.com/kalmbach/bury?Info
The text was updated successfully, but these errors were encountered: