Skip to content

Add note on how to submit a form#6594

Merged
jimfb merged 1 commit intofacebook:masterfrom
SimenB:patch-1
Apr 28, 2016
Merged

Add note on how to submit a form#6594
jimfb merged 1 commit intofacebook:masterfrom
SimenB:patch-1

Conversation

@SimenB
Copy link
Copy Markdown
Contributor

@SimenB SimenB commented Apr 23, 2016

This is just me overthinking it coming from jQuery, but googling how to submit a form gave me nothing, so I thought I'd add this.

Our use case was solved when I took a step back and just put a submit button into the form (which is why I included that example as well), but I can see use cases for programmatically doing it, in all cases when a form is submitted without user input, or at least where the input is not pressing a button/link. And as mentioned, googling didn't give me anything.

Comment thread docs/docs/07-forms.md Outdated
>
> You can pass an array into the `value` attribute, allowing you to select multiple options in a `select` tag: `<select multiple={true} value={['B', 'C']}>`.

### Submit form
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let’s change this to Submitting a Form

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@gaearon
Copy link
Copy Markdown
Collaborator

gaearon commented Apr 28, 2016

Thanks! I left a few comments but I agree we should add this.

@jimfb
Copy link
Copy Markdown
Contributor

jimfb commented Apr 28, 2016

@gaearon I have slightly more mixed feelings about this PR. I tend to think it's probably sufficient to give the user a nudge in the direction of using refs, but a full fledged example here seems like overkill. Especially since there are many other equally valid use cases for using events. For instance, suppose you want to imperatively clear an uncontrolled component.

I feel like I would just collapse this whole section into two sentences:

If you need to imperatively perform an operation, you have to obtain a reference to the DOM node. For instance, if you want to imperatively submit a form, one approach would be to attach a ref to the form element and manually call form.submit().

@gaearon Thoughts? I don't feel strongly one way or the other. It's just that attaching refs is intended as an escape hatch instead of an endorsed pattern, so a little side-note seems sufficient.

@gaearon
Copy link
Copy Markdown
Collaborator

gaearon commented Apr 28, 2016

I also had mixed feelings so I side with @jimfb.

@SimenB
Copy link
Copy Markdown
Contributor Author

SimenB commented Apr 28, 2016

Good suggestion, that note would have been enough for me. I just stole those sentences, should the header be changed as well (beyond @gaearon's suggested change)? Imperative operations? I just do ctrl/cmd+f and write out submit, so that'd be enough for me, but I don't know

@SimenB SimenB force-pushed the patch-1 branch 2 times, most recently from e6be99f to da81b16 Compare April 28, 2016 06:03
@ghost
Copy link
Copy Markdown

ghost commented Apr 28, 2016

@SimenB updated the pull request.

@jimfb
Copy link
Copy Markdown
Contributor

jimfb commented Apr 28, 2016

Yeah, we should probably update the header. The title "Imperative operations" sounds fine to me.

@SimenB
Copy link
Copy Markdown
Contributor Author

SimenB commented Apr 28, 2016

Done

@jimfb
Copy link
Copy Markdown
Contributor

jimfb commented Apr 28, 2016

👍

@jimfb jimfb self-assigned this Apr 28, 2016
@jimfb jimfb merged commit 7724681 into facebook:master Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants