Reputation: 913
I use Bootstrap3 Modal. I bind the 'hidden.bs.modal' with a handler, but in a special case I need to just close modal without call the hidden handler, after that, next time user open the modal and close it again, then hidden handler get called as normal:
//suppose modal is shown, unbind first to prevent the handler run
$('..').unbind('hidden.bs.modal');
$('..').modal('hide');
//rebind the handler
$('..').bind('hidden.bs.modal',function(){//...});
But seems not to work: it still calls the handler. Is there a way to achieve this?
Thanks
Upvotes: 1
Views: 2566
Reputation: 3740
I felt same problem earlier and used this hackish to prevent calling hidden callback in some cases. hope it will help you
function close_modal_without_callback() {
$('#myModal').off('hidden.bs.modal');//`off` to remove event handler attached with `on`
$('#myModal').modal('hide'); // hide modal
setTimeout(function() { //to add little delay to reattach the event
$('#myModal').on('hidden.bs.modal', function(e) {
hidden_handler(); //handler function
});
}, 1000);
}
Upvotes: 2