Show hidden bootboxjs dialog

408 Views Asked by At

I create a modal dialog via bootboxjs, with option show: false

  bootbox.dialog({
    message: "Whatever",
    show: false,
  });

How can I then show that dialog (e.g. on a click event)?

Thanks!

1

There are 1 best solutions below

0
On

I haven't used Bootbox before, but after looking at the source, you add the data-bb="dialog" attribute onto the button. Then, define a click function at the top of your script:

Note: I am using demo namespace. I saw it in the source they were using on the page. So change this

$(function() {
    var demos = {}; // object namespace

    $(document).on("click", "a[data-bb]", function(e) { // all buttons that have this attribute
        e.preventDefault();
        var type = $(this).data("bb"); // get what type it is (alert, dialog, etc.)

        if (typeof demos[type] === 'function') {
            demos[type](); // run that type (demos.alert(), demos.dialog(), etc.)
        }
    });

    demos.dialog = function() {
       bootbox.dialog({
          message: "Whatever"
       });
    };
});

Hope this helps in some way