Hi ! This is a rewriting of automatically closed issue https://github.com/jaredpalmer/formik/issues/657 that contained 10+ participants
When I'm working with deep nested elements, values[element.name] obviously does not work.
It should be easy to get form values, even when deep nested
add a getFieldValue helper that would work with deep nested fields and fieldList. It would use something similar as 'lodash's get
I had to add a custom function to do this with my deep nested field
export function getObjectValue(obj, path) {
var fullPath = path
.replace(/\[/g, '.')
.replace(/]/g, '')
.split('.')
.filter(Boolean);
return fullPath.every(everyFunc) ? obj : null;
function everyFunc(step) {
return !(step && (obj = obj[step]) === undefined);
}
}
thank you 馃敟 !
There is a getIn function that formik exports that you can use, however it is not documented.
import { getIn } from 'formik'
function example(formik) {
const value = getIn(formik.values, 'path.to.value');
// do something with value.
}
This does exactly what your helper function does, though it should be officially documented.
It's also useful for accessing the touched and errors for a particular name too.
Most helpful comment
There is a
getInfunction that formik exports that you can use, however it is not documented.This does exactly what your helper function does, though it should be officially documented.
It's also useful for accessing the touched and errors for a particular name too.