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

Submit form from outside #13

Closed
romanlex opened this issue Nov 29, 2017 · 9 comments
Closed

Submit form from outside #13

romanlex opened this issue Nov 29, 2017 · 9 comments

Comments

@romanlex
Copy link

Hello. How I can submit form from outside sibling component? Example I want submit form by button from modal window

@romanlex
Copy link
Author

Now I use Portal https://gist.github.com/romanlex/bf61fb0c3db2ef1a6c68cb07a0904da2 but I think need remote submit method (

@erikras
Copy link
Member

erikras commented Nov 29, 2017

Wow, look at you using <Fragment> already! 😮

Can you not pass handleSubmit to your portal component?

@romanlex
Copy link
Author

romanlex commented Nov 30, 2017

if I remove handleSubmit my button doesnt work because buttons render to another domNode with Ract.createPortal

        <CallbackForm
          buttonPortalId={containerActionId}
          subscription={{ submitting: true, pristine: true }}
        />
        <footer
          className="divider-block__footer-actions"
          id={containerActionId}>
              // my buttons
       </footer>

@erikras
Copy link
Member

erikras commented Dec 1, 2017

It's not very React-y, but I wonder if you could use the DOM itself to achieve this, by calling submit()?

<form id="myForm" onSubmit={handleSubmit}> ... </form>
...
<button type="button" onClick={() => document.getElementById('myForm').submit()}>
  Submit
</button>

@codepunkt
Copy link

@romanlex it seems we ran into similar problems.

For me, calling .submit() on the form did not work & reloaded the whole app.
See this tweet for more information on how i solved it.

Maybe you can even chime in and tell me why the heck the things i did actually worked, when .submit() doesn't.

@erikras erikras closed this as completed Dec 4, 2017
@elrumordelaluz
Copy link

Beyond this little issue, the switch from redux-form into react-final-form seems really simple.
Thanks @erikras for the great work!

Thanks @romanlex for the workaround, I am also pretty curious on why only this way works as expected.

@erikras
Copy link
Member

erikras commented Dec 13, 2017

Made a FAQ about this.

@romanlex
Copy link
Author

romanlex commented Dec 14, 2017

Hello! Why I use Portal but not use document.getElementById() or submit by Closure?
Because I want use native state by react-final-form without any HOC with custom form state
I want disable button or use another function.

      <button
              className="btn btn-outline-secondary btn-block"
              type="button"
              onClick={reset}
              disabled={submitting || pristine}>
              Reset form
      </button>
      <button
              className="btn btn-primary btn-block"
              type="submit"
              onClick={handleSubmit}
              disabled={submitting}>
              Submit
       </button>

@lock
Copy link

lock bot commented Dec 14, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Dec 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants