console.log(r); gets nothing. How can I pass the result to r variable when using bootbox
function jconfirm(m){
bootbox.confirm({
message: m,
buttons: {
'cancel': {
label: 'No'
},
'confirm': {
label: 'Yes',
}
},
callback: function(result) {
return result;
}
});
}
jconfirm('Do you really ....', function(r){
console.log(r);
});
You could try this approach:
var jconfirm = function (message, callback) {
var options = {
message: message
};
options.buttons = {
cancel: {
label: "No",
className: "btn-default",
callback: function(result) {
callback(false);
}
},
main: {
label: "Yes",
className: "btn-primary",
callback: function (result) {
callback(true);
}
}
};
bootbox.dialog(options);
};
$('#delete').on('click', function (e, confirmed) {
if (!confirmed) {
e.preventDefault();
jconfirm("Do you really ....", function (r) {
console.log(r);
if (r) {
$('#delete').trigger('click', true);
}
});
}
});
$('#form').submit(function (e) {
//do your validation or whatever you need to do before submit
});
JSFiddle
//You may also can use this is working for me.
//Call function
confirm_boot('Delete','Are you sure? ', function(result) {
console.log("Confirmed? " + result);
});
//define function
var confirm_boot = function(title, msg,callback) {
bootbox.confirm({
title: title,
message: msg,
buttons: {
cancel: {
label: '<i class="fa fa-times"></i> Cancel',
},
confirm: {
label: '<i class="fa fa-check"></i> Confirm',
}
},
callback: function(result) {
console.log('This was logged in the callback: ' + result);
callback(result);
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With