Unfortunately, the doc Bootbox ( http://paynedigital.com/2011/11/bootbox-js-alert-confirm-dialogs-for-twitter-bootstrap ) not teach how to call the confirm dialog. As it is in the doc window always appears when the page is loaded, what is wrong, should appear when called by clicking on a delete button. This is the code that tried unsuccessfully.
// show "false" does not work, the confirm window is showing when page is loaded.
$(function () {
bootbox.confirm("Confirm delete?", "No", "Yes", function(result) {
show: false
});
});
// need show the confirm window when the user click in a button, how to call the confirm window?
<td><a class="icon-trash" onclick="bootbox.confirm();" href="{% url 'del_setor' setor.id %}" title="Delete"></a></td>
How do I set this bootbox to appear only when the delete button is clicked? Thanks!
EDIT -SOLUTION:
$(function () {
$("a#confirm").click(function(e) {
e.preventDefault();
var location = $(this).attr('href');
bootbox.confirm("Confirm exclusion?", "No", "Yes", function(confirmed) {
if(confirmed) {
window.location.replace(location);
}
});
});
});
Now, the deletion works when i click in "yes". I asked the developers of the plugin to put the full sample in the doc, so users do not need to create posts about how to remove the object when "yes" is clicked. Regards.
You may want to check the source on the "Confirm" link under "Basic Usage" on this page: http://bootboxjs.com/
Here's a snippet:
$("a.confirm").click(function(e) {
e.preventDefault();
bootbox.confirm("Are you sure?", function(confirmed) {
console.log("Confirmed: "+confirmed);
});
});
Assuming jQuery is available in the UI you're working on, I'd avoid using an onClick
attribute in your anchor tags. Just my two cents.