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

How to programatically submit a <Form> component #1348

Closed
achimkoellner opened this issue Feb 19, 2017 · 3 comments
Closed

How to programatically submit a <Form> component #1348

achimkoellner opened this issue Feb 19, 2017 · 3 comments

Comments

@achimkoellner
Copy link

Please add documentation on how to programatically submit a

component.
I guess it's about adding a ref and calling submit on it or is there another option?

@levithomason
Copy link
Member

levithomason commented Feb 21, 2017

Manually call the method that you'd otherwise pass to the onSubmit prop. You should capture your form data in state using form control onChange handlers.

PRs welcome :)

@dvdzkwsk
Copy link
Member

dvdzkwsk commented Feb 21, 2017

Also, unless it's explicitly documented, you should avoid using internal methods of the form (or any other) component. This is because doing so means reaching through what should be an opaque abstraction into internal methods that may change at any time.

So, unless these methods become a formal part of the public API, it's likely best to follow @levithomason 's advice. Furthermore, it's generally bad practice to reach downward through the React tree in order to initiate side effects.

@levithomason
Copy link
Member

FWIW, I actually plan to remove the onSubmit handler as it has caused lots of confusion and encouraged bad practice. The current implementation is DOM based anyhow, which just makes it this much worse.

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

3 participants