Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not submit form react-bootstrap

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?

like image 948
octavian Avatar asked Sep 05 '25 17:09

octavian


2 Answers

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>
like image 140
madox2 Avatar answered Sep 07 '25 13:09

madox2


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
}
like image 21
ajamardo Avatar answered Sep 07 '25 11:09

ajamardo