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

Custom component without <input /> #306

Closed
ancashoria opened this issue Dec 12, 2017 · 3 comments
Closed

Custom component without <input /> #306

ancashoria opened this issue Dec 12, 2017 · 3 comments

Comments

@ancashoria
Copy link

Is it possible to use Formik for react components that don't rely on html <input /> field?

My component is a custom selector that relies only on <div> and <span> elements.
Right now Formik event handler assumes the presence of event.name, which is fine for input components, but for div elements I can't set name on them because it's not valid.

Formik is really great for us, but this is quite a blocker right now.
How should we handle this?

Thanks

@ancashoria
Copy link
Author

ancashoria commented Dec 12, 2017

So far I have managed to work around it, but it's really hackish.
Here's my solution:

(e) => {
  e.target.name = "nameOfThePropIWantFormikToUpdate"
  e.target.value = "valueOfThatProp"
  this.props.handleChange(e)
}

@jaredpalmer
Copy link
Owner

Use setFieldValue, it’s built just for this

@ancashoria
Copy link
Author

Thank you so much.
Formik is great

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

No branches or pull requests

2 participants