question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple Submit Buttons?

See original GitHub issue

Hello Formsy React/Christian,

Can we do the following:

<button type="submit" name="save" value="save-and-continue" className="btn btn-default save-and-continue" disabled={!this.state.canSubmit}>
    {loadingIcon}
    Save &amp; Continue
</button>

<button type="submit" name="save" value="save-and-add" className="btn btn-default save-and-add" disabled={!this.state.canSubmit}>
     {loadingIcon}
     Save &amp; Add Another
</button>

 <button type="submit" name="save" value="save-and-return" className="btn btn-primary save-and-return" disabled={!this.state.canSubmit}>
    {loadingIcon}
    Save &amp; Return to List
</button>

Only the value that was clicked would be passed through in the model onSubmit so if the second button above was clicked we’d get {save: ‘save-and-add’} in our form data?

What do you think? Useful?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
christianalfonicommented, Jul 28, 2015

Hi there!

You can solve this by manually submitting the form 😃

Quick example:

onSubmit: function (model) {
  if (this.state.typeOfSubmit === 'oneOfThem') {
    // doe something
  }
},
submit1: function () {
  this.setState({
    typeOfSubmit: 'oneOfThem'
  }, this.refs.form.submit);
},
submit2: function () {
  this.setState({
    typeOfSubmit: 'theOther'
  }, this.refs.form.submit);
},
render: function () {
  return (
    <Formsy.Form onSubmit={this.onSubmit} ref="form">
      <button onClick={this.submit1}>Submit1</button>
      <button onClick={this.submit2}>Submit2</button>
    </Formsy.Form>
  );
}

Would that work for you?

0reactions
nyecommented, Feb 24, 2016

@christianalfoni But now you don’t have a submit button, so you can’t submit on press enter key?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Two submit buttons in one form - Stack Overflow
The best way to deal with multiple submit buttons is using a switch case in the server script <form action="demo_form.php" method="get"> ...
Read more >
How to use multiple submit buttons in an HTML form
How to use multiple submit buttons in an HTML form ? · Create a form with method 'post' and set the value of...
Read more >
Using Multiple Submit Buttons With A Single Form
Using Multiple Submit Buttons With A Single Form · Option 1 – Buttons With Same Name, Different Text · Option 2 – Different...
Read more >
How can I use multiple submit buttons in an HTML form?
yes, multiple submit buttons can include in the html form. One simple example is given below. Here I am using MVC VB.net.In view...
Read more >
Separate Form Submit Buttons That Go To Different URLs
When you submit that form, it's going to go to the URL `/submit`. Say you need another submit button that submits to a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found