Formik: Add `field.error` and `field.touched` support to `<Field>`

Created on 5 Oct 2018  路  4Comments  路  Source: formium/formik

I'm pretty new to Formik, but one of the things I loved about it right away was the ability to wrap existing form field components with a <Field> and then use value={field.value} on my field component's props.

My field components also display stylized errors if passed to the error prop. I first tried accessing the field's error value using field.error, but eventually realized I couldn't get the field's error value that way, and would need to use the form prop.

Unfortunately (and this may be a separate issue), using form.errors[field.name] did not work for me, but using the lodash-style getIn(form.errors, field.name) did work. I suspect this might be due to nested-arrays in my values/errors model, but I have not yet had time to prove this out.

Suggested Solution

So I'm suggesting that field should support field.error and field.touched as convenience handles over using form.errors or form.touched. Also be sure these accessors will work when there are nested arrays in the form model.

Example:
When:
field.name = parents[0].children[0].firstName,
and
field.value = form.values.parents[0].children[0].firstName
then:
field.error = form.errors.parents[0].children[0].firstName
and
field.touched = form.touched.parents[0].children[0].firstName

Who does this impact? Who is this for?

As a Formik beginner I think this would make things simpler for other beginners.

Duplicate

Most helpful comment

In Formik 2, a meta property is in discussion (it would be breaking). The other idea is to provide a getFieldMeta getter function.

All 4 comments

In Formik 2, a meta property is in discussion (it would be breaking). The other idea is to provide a getFieldMeta getter function.

Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal.

I find this proposal quite convenient! Please don't cl贸set this issue Mr. Bot xD

Was this page helpful?
0 / 5 - 0 ratings

Related issues

najisawas picture najisawas  路  3Comments

outaTiME picture outaTiME  路  3Comments

ancashoria picture ancashoria  路  3Comments

PeerHartmann picture PeerHartmann  路  3Comments

Jungwoo-An picture Jungwoo-An  路  3Comments