Skip to content

Programmatically submit a Microcosm <Form> #170

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

Closed
greypants opened this issue Oct 25, 2016 · 0 comments
Closed

Programmatically submit a Microcosm <Form> #170

greypants opened this issue Oct 25, 2016 · 0 comments

Comments

@greypants
Copy link
Contributor

greypants commented Oct 25, 2016

There are times where you might want to submit a form programmatically from an external component, or a special event, like submitting on enter keyDown from a <textarea />, which isn't the default behavior. onSubmit calls event.preventDefault() isn't needed in this case, so we would need to break out a separate submit method, which doesn't rely on the presence of event.

Example:

    <div>
      <Form ref={form => this.form = form} intent="updateMessage">
      </Form>
      <button type="button" onClick={() => this.form.submit()}>Save</button>
    <div>

I tried using refs and doing findDOMNode(this.refs.form).submit(), but the form submits (and refreshes the page) without triggering the internal onSubmit callback, which prevents default 😕

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

1 participant