Can not submit form react-bootstrap

Can not submit form react-bootstrap

I have the following react-bootstrap component:



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?

Solutions/Answers:

Solution 1:

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>

Solution 2:

There is one thing missing, I think.

In gotEmail, there should be a preventDefault, so if the user press ‘enter’, the page won’t reload:

gotEmail(event){ 
  event.preventDefault();
  // code you want to do
}

Solution 3:

As of version 0.30.2, you can wrap it in a <Form>, which supports the onSubmit property:

<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>

Solution 4:

I’ve found success with raectstrap using:

<Button onClick={this.onSubmit}>Login</Button> 

Related:  bootstrap datepicker change date event doesnt fire up when manually editing dates or clearing date

References