Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48357

Modal it is open multiple times

I'm using bootbox library. I have one button called Delete.

$('body').on("click", ".deleteDiagnostic", function () {
        var id = $(this).attr("data-diagnosticID");
        var currentRow = $(this).closest('tr');
        bootbox.confirm("Are you sure want to delete?", function (result) {
            if (result == true) {
                //code here
            }
        });
});

I'm also using PartialView and the page which contains button is loaded dynamically. Sometimes when I click, bootbox is open multiple times and I don't know why.

PS: When I load PartialView for first time it's working perfectly, but when I load PartialView multiple times, then bootbox appears multiple times on button click.

Upvotes: 2

Views: 1353

Answers (1)

Martino Lessio
Martino Lessio

Reputation: 781

Please try to modify your code like this:

$('body').on("click", ".deleteDiagnostic", function (evt) {
    evt.stopImmediatePropagation();

    var id = $(this).attr("data-diagnosticID");
    var currentRow = $(this).closest('tr');
    bootbox.confirm("Are you sure want to delete?", function (result) {
        if (result == true) {
            //code here
        }
    });
});

Upvotes: 5

Related Questions