Reputation: 340
I am using a bootstrap modal in my react component like so...
<button data-toggle="modal" data-target="#myModal">
Let's Start
</button>
<div id="myModal" className="modal fade" tabindex="-1" data-backdrop="static" role="dialog" >
<div className="modal-dialog modal-dialog-centered" style={{overflowY:"initial !important"}}>
<div class="modal-content" style={{width:"fit-content"}} >
<div className="modal-header">
<Header icon="add to calendar" content="Modal Header" />
<button type="button" className="close" data-dismiss="modal">×</button>
</div>
<div className="modal-body" style={{overflowY:"auto",padding:"4em"}}>
Body Here
</div>
<div className="modal-footer">
<button onClick={this.handleClick}>Submit</button>
</div>
</div>
</div>
</div>
The modal contains a form and the button in the footer handles submit. I want to validate the input and close the modal only if validation is successful or else display an error message. How do I close the modal from inside a function?
What I have tried (and what went wrong) :
document.getElementById("myModal").modal("toggle")
(turns out it's useless with virtualDOM)Is there any way at all I can achieve this with just react and bootstrap?
Help is much appreciated. Thanks.
Upvotes: 0
Views: 3025
Reputation: 51
You can try my solution.
Upvotes: 1