1

Hi I am sending some information from my modal to my php server. Until the php server does not respond, I do not want the modal being closed in any way (clicking outside, pressing ESC, clicking on close buttons etc). So I have used the following code:

$('#modal').on('hide.bs.modal', function (e) {
   e.preventDefault();
});

Once the server has responded, how can I revert to the default behaviour of the modal? I tried the following but it does not work:

$('#modal').on('hide.bs.modal', function (e) {
   return true;
});
M9A
  • 3,168
  • 14
  • 51
  • 79
  • hey you can get some info here abiut this preventDefault method https://stackoverflow.com/questions/1551389/how-to-unbind-a-listener-that-is-calling-event-preventdefault-using-jquery – Ashish sah Aug 15 '17 at 22:11
  • did you try to use $('#yourModal').modal({'backdrop': 'static'}) and closing with jquery when you get response from server-side; – hasan Aug 15 '17 at 22:26

1 Answers1

2

How about this approach? Set a variable submitting to true before you execute the ajax request and back to false after it's done.

$('#modal').on('hide.bs.modal', function (e) {
    if (submitting) {
        e.preventDefault();
    }
});
Maarten van Tjonger
  • 1,867
  • 1
  • 10
  • 15