Formik: Only post touched fields

Created on 19 Mar 2019  路  4Comments  路  Source: formium/formik

鉂換uestion

Hey, does anyone have an example of how to only submit touched values. I'm currently using the formik HOC but the handleSubmit function doesn't have access to the touched prop.

stale

Most helpful comment

Hi, I need a granular field update as well and can't figure out how to do that. I'm using <Formik> component and there's no touched on the onSubmit's formikBag object.

Is there a specific reason why it's not present there? Just to be clear, documentation is quite honest about it but doesn't mention any particular reason:

Note: errors, touched, status and all event handlers are NOT included in the FormikBag.

All 4 comments

If you are using withFormik HOC, it's handleSubmit have second argument with formikBag and props passed to component, including touched:

const formikEnhancer = withFormik({
  handleSubmit: (payload, bag: { props: { touched } }) => {
     console.log(touched);
  },
  displayName: "MyForm",
});

But all fields (that mentioned in initialValues) will be marked as touched on submit. So it will not help.

@funkyskank thanks, can鈥檛 believe I missed that.

It鈥檚 certainly a workaround but I could set up the equivalent of a hidden field in web land and populate via the fields that get touched.

Agree, this would be interesting in regards of atomic (database) updates.

Hi, I need a granular field update as well and can't figure out how to do that. I'm using <Formik> component and there's no touched on the onSubmit's formikBag object.

Is there a specific reason why it's not present there? Just to be clear, documentation is quite honest about it but doesn't mention any particular reason:

Note: errors, touched, status and all event handlers are NOT included in the FormikBag.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

najisawas picture najisawas  路  3Comments

outaTiME picture outaTiME  路  3Comments

jaredpalmer picture jaredpalmer  路  3Comments

giulioambrogi picture giulioambrogi  路  3Comments

dfee picture dfee  路  3Comments