Post-Image

Bootbox.js – Alerts with callbacks for Bootstrap

Posted on

Some time ago I searched for a plugin with which I could add modals with input fields to my websites and interpret the callback.

This was when I found http://bootboxjs.com/ a library which provides exactly this function. Using it is super simple:

bootbox.confirm("Do you want to delete this?",
function(result) {
  alert(result);
});

But you can also create custom dialogs:

bootbox.dialog({
  message: "I am a custom dialog",
  title: "Custom title",
  buttons: {
    success: {
      label: "Success!",
      className: "btn-success",
      callback: function() {
        alert('success');
      }
    },
    danger: {
      label: "Danger!",
      className: "btn-danger",
      callback: function() {
        alert('dangerzone');
      }
    },
    main: {
      label: "Click ME!",
      className: "btn-primary",
      callback: function() {
        alert('primary');
      }
    }
  }
});

Still not convinced? Try out some more examples or visit the main plugin site: http://bootboxjs.com/

Leave a Reply