Ravi Brahmbhatt
Ravi Brahmbhatt

Reputation: 93

Bootstrap Modal method fires multiple times

I am facing issue with bootstrap modal. I have implemented the below code. I do not know what is happening but on first time when i click "YES" button it is working fine but when i click on NO button and after that when i click yes button ,the yes button click event gets fired mutliple times. I have no clue why is this happening.

$('#confirmationModal').modal('show');
$("#confirmationModal").on('shown.bs.modal', function() {
  $('#confirmationModal').modal({
    backdrop: 'static',
    keyboard: false
  }).one('click', '#yesbutton', function(e) {
    $('#confirmationModal').modal('hide');

    //Doing Ajax Stuff and alert data.    

    //Very important line.
    //This is needed to prevent multiple firing of the yes button event.

    $(this).off(event);

  })
}); * * strong text * *

Upvotes: 1

Views: 1348

Answers (1)

Ravi Brahmbhatt
Ravi Brahmbhatt

Reputation: 93

I think the issue was that event was getting registered multiple times as the above code is getting called on another click event of every row of the table.

Hence , I solved this issue by registering the click event explicitly for the yes and no button and calling only modal.show() to display the confirmation dialog.

Upvotes: 1

Related Questions