Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
576 views
in Technique[技术] by (71.8m points)

javascript - Change backdrop to static for open bootstrap modal

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 that is the moment when I want to change backdrop to static

I tried $('#myModal').modal({backdrop: 'static', keyboard: false}), but I can still close my modal by clicking the backdrop or using escape button.

Second step should be changing backdrop back to true, but I didn't try this yet, because first I need to set backdrop to static.

I could set backdrop to static on modal show, but I want to avoid this and change it after submit.

Any ideas?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...