Hello i try to use a confirm Bootstrap Modal in a Button Formatter jqgrid
function buttonFormatter(cellvalue, options, rowobject)
{
var id = rowobject.Id;
return '<button id="button1_'+ id+ '"class="btn btn-danger btn-large" style="width:100%" onclick="buttonClick(this.id); return false;"><i class="fa fa-times"></i> ModalPopupShow</button>';
}
function buttonClick(buttonId)
{
var res = buttonId.split("_");
var id = res[res.length - 1];
$('#modal1').modal('show');
var modalConfirm = function (callback) {
$("#buttonModal1").on("click", function (e) {
callback(true);
$("#modal1").modal('hide');
});
$("#buttonModal2").on("click", function () {
callback(false);
$("#modal1").modal('hide');
});
};
modalConfirm(function (confirm) {
if (confirm) {
alert("confirmado - " + id);
} else {
alert("Não confirmado");
}
});
}
But I have multiple callbacks. I click once show one alert if i click another time two alerts, another click three alerts and so on...
What is the best way to avoid this behavior?
Tnks