Skip to content
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

Add field.error and field.touched support to <Field> #963

Closed
CodingDutchman opened this issue Oct 5, 2018 · 4 comments
Closed

Add field.error and field.touched support to <Field> #963

CodingDutchman opened this issue Oct 5, 2018 · 4 comments

Comments

@CodingDutchman
Copy link

CodingDutchman commented Oct 5, 2018

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.

@CodingDutchman CodingDutchman changed the title Add field.error and field.touched support to field prop of `<Field> Add field.error and field.touched support to field prop of <Field> Oct 5, 2018
@CodingDutchman CodingDutchman changed the title Add field.error and field.touched support to field prop of <Field> Add field.error and field.touched support to <Field> Oct 5, 2018
@jaredpalmer
Copy link
Owner

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

@stale
Copy link

stale bot commented Dec 9, 2018

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.

@stale stale bot added the stale label Dec 9, 2018
@wild-lotus
Copy link

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

@stale stale bot removed the stale label Dec 9, 2018
@penx
Copy link

penx commented Jan 16, 2019

This is a duplicate of the following:

#343
#828
#579

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants