I got several user input fields inside Bootstrap Modal and I'm trying to do some validation before users can submit it.
I've looked around several related articles and nothing has worked for me so far.
So the main problem that I'm having is that, everytime I press submit, the modal window closes so that users cannot see the error messages. I want the modal window to stay open until a successful submission occurs.
Below is my modal
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#editModal" style="float:right">
<span class="glyphicon glyphicon-edit"></span> Edit
</button>
<!-- Modal -->
<div class="modal fade" id="editModal" role="dialog" >
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content" >
<div class="modal-header" >
<button type="button" class="close" data-dismiss="modal">×</button>
<h4>Edit Your Login Information</h4>
</div>
<div class="modal-body">
<form action="{{ url_for('.profile') }}" method='post' name='edit_user' class="form-horizontal" >
{{ user_edit_form.csrf_token }}
<div class="form-group col-xs-12 col-md-12 col-lg-12" style="background-color:white; !important ">
<div class="col-xs-12 col-md-12 col-lg-12" >
{{ render_field(user_edit_form.first_name) }}
</div>
<div class="col-xs-12 col-md-12 col-lg-12">
{{ render_field(user_edit_form.last_name) }}
</div>
<div class="col-xs-12 col-md-12 col-lg-12">
{{ render_field(user_edit_form.email) }}
</div>
<div class="col-xs-12 col-md-12 col-lg-12">
{{ render_field(user_edit_form.institute) }}
</div>
<div class="col-xs-12 col-md-12 col-lg-12">
<input class='btn btn-primary' id='uform' type='submit' value='UPDATE' style="float:right"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
and the javascript that I'm trying to get it to work
<script>
var formErrors = {% if user_edit_form.errors %}true{% else %}false{% endif %};
$(document).ready(function() {
if (formErrors) {
$('.Modal').modal('show');
}
});
</script>
Any help will be really appreciated!!