Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

[Feature request] give possibility to place <button type="submit"> inside generated form #95

Closed
dearlordylord opened this issue Apr 4, 2015 · 2 comments

Comments

@dearlordylord
Copy link
Sponsor

I find it strange there's no such request. Am I overlooked it?

Case is like this: I create form like that:

<Form .../>
<button type="submit"/>

Problem is, when focus is inside any input, and I click 'enter', button submit doesn't being clicked (and it shouldn't as it isn't inside

.

I'd like to have possibility to have this button inside, not using custom templates / custom components.

@gcanti
Copy link
Owner

gcanti commented Apr 4, 2015

The output of the Form component is a fieldset tag containing the fields. You can add a form tag wrapping the output:

<form action="..." method="..." or onSubmit={...}>
  <Form ... />
  <button type="submit"/>
</form>

Complete example if you want to send the form via HTTP

var Person = t.struct({
  name: t.Str,
  surname: t.Str
});

var App = React.createClass({

  onSubmit(evt) {
    var value = this.refs.form.getValue();
    if (!value) {
      // there are errors, don't send the form
      evt.preventDefault();
    } else {
      // everything ok, let the form fly...
      // or handle the values contained in the `value` variable with js
    }
  },

  render() {

    return (
      <form onSubmit={this.onSubmit}>
        <Form
          ref="form"
          type={Person}
        />
        <button type="submit">Save</button>
      </form>
    );
  }

});

React.render(<App />, document.getElementById('app'));

@dearlordylord
Copy link
Sponsor Author

Thanks!

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

2 participants