prevent bootstrap modal window from closing on form submission

后端 未结 7 1823
轻奢々
轻奢々 2021-02-05 06:47

Hi I\'m using Bootstrap for the first time and I can\'t get my modal form to stay open on clicking the submit button. I\'ve searched SO but all related questions deal with slig

7条回答
  •  不思量自难忘°
    2021-02-05 07:06

    I ran into the similar problem where I use modal as a form so I cannot initially set data-backdrop="static" data-keyboard="false" because I want the user to be able to close it as long as he has not submitted the form. Once he has submitted the form, I want to prevent him from closing the form modal. Here is how I can get around.

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

提交回复
热议问题