Change backdrop to static for open bootstrap modal

后端 未结 5 2073
感情败类
感情败类 2020-12-19 05:33

Can I change backdrop to \'static\' while my modal is open?

I have modal with form submit button. When I click this button I show loading spinner on my modal and th

5条回答
  •  攒了一身酷
    2020-12-19 06:13

    Ok I solved this. Maybe it is not the best solution, but it is working for my special case.

    I added $('#myModal').off('click'); just after I show loading spinner on submit. This prevents from closing modal with mouse click.

    There was a problem with disabling escape button, because browsers stops page loading when user press this button. So I decided to hide the spinner to unlock the form with this code:

    $(document).on('keydown',function(e) {
      if (e.keyCode == 27) {
        $('#myLoadingSpinner').hide();
      }
    });
    


    Edit: I found another solution for backdrop:

    $('#myModal').data('bs.modal').options.backdrop = 'static';
    

    I tried this also for keyboard = false, but it doesn't work.

提交回复
热议问题