Can not submit form react-bootstrap

octavian picture octavian · May 15, 2016 · Viewed 27.7k times · Source

I have the following react-bootstrap component:

        <FormGroup onSubmit={this.gotEmail} role="form">
          <FormControl type="text" className="form-control"/>
          <Button className="btn btn-primary btn-large centerButton" type="submit">Send</Button>
        </FormGroup>

I would like the form to be submitted when I click the button "Send".

However, if I click the button, control doesn't reach the this.gotEmail method.

Why is that the case?

Answer

madox2 picture madox2 · May 15, 2016

FormGroup does not provide on submit event. You can wrap it with form element and attach event handler to it:

<form onSubmit={this.gotEmail}>
  <FormGroup role="form">
    <FormControl type="text" className="form-control"/>
    <Button className="btn btn-primary btn-large centerButton" type="submit">Send</Button>
  </FormGroup>
</form>