I am showing a Bootstrap modal window for loading when performing AJAX calls. I broadcast a \"progress.init\" event when the loading modal should show and a \"progress.finis
Add data-backdrop="false"
option as an attribute to the button which opens the modal.
See How to remove bootstrap modal overlay?
If the close dismiss button is working but the problem occurs when using dynamic code such as modal('hide') you can use this code. forcing the backdrop to totally remove.
for Bootstrap 3
$modal.on('hidden.bs.modal', function(){
//remove the backdrop
jQuery('[data-dismiss="modal"]').click();
});
yourbutton.click(function() {
$modal.modal('hide');
});
Workaround is to hide the backdrop entirely if you don't need one like this: data-backdrop=""
<div class="modal fade preview-modal" data-backdrop="" id="preview-modal" role="dialog" aria-labelledby="preview-modal" aria-hidden="true">
So if you don't want to remove fade or tinker with the dom objects, all you have to do is make sure you wait for the show to finish:
$('#load-modal').on('shown.bs.modal', function () {
console.log('Shown Modal Backdrop');
$('#load-modal').addClass('shown');
});
function HideLoader() {
var loadmodalhidetimer = setInterval(function () {
if ($('#load-modal').is('.shown')) {
$('#load-modal').removeClass('shown').modal('hide');
clearInterval(loadmodalhidetimer);
console.log('HideLoader');
}
else { //this is just for show.
console.log('Waiting to Hide');
}
}, 200);
}
IMO Bootstrap should already be doing this. Well perhaps a little more, if there is a chance that you could be calling hide without having done show you may want to add a little on show.bs.modal add the class 'showing' and make sure that the timer checks that showing is intended before getting into the loop. Make sure you clear 'showing' at the point it's shown.
An issue I was having (may help someone) was simply that I was using a partial to load the Modal.
<li data-toggle="modal" data-target="#priceInfoModal">
<label>Listing Price</label>
<i class="fa fa-money"></i>
@Html.Partial("EditPartials/PriceInfo_Edit")
</li>
I had placed the partial call inside the same list item So data-target="#priceInfoModal" and div id="priceInfoModal" were in the same container causing me to not be able to close my modal
Use a close button in modal, this method is working fine:
<input type="button" class="btn btn-default" data-dismiss="modal" value="Cancel" id="close_model">
After success use:
$('#model_form').trigger("reset"); // for cleaning a modal form
$('#close_model').click(); // for closing a modal with backdrop