cssbootstrap-4bootbox

"CenterVertical" property does not position the modal bootbox in the center of the screen


need to center a modal bootbox window vertically in the center of the screen, but the "centerVertical" property is not complying. Does anyone know how to solve this?

Thanks :)

bootbox.dialog({
    message: "I am a custom dialog",
    title: "Custom title",
    //size: "large",
    //centerVertical: true,
    //backdrop: true,
    centerVertical: true,
    size: "small",
    buttons: {
        success: {
            label: "Success!",
            className: "btn-success",
            callback: function callback() {
                toastr.info("great success");
                alert('ok')
            }
        },
        danger: {
            label: "Danger!",
            className: "btn-danger",
            callback: function callback() {
                toastr.info("uh oh, look out!");
            }
        },
        main: {
            label: "Click ME!",
            className: "btn-primary",
            callback: function callback() {
                toastr.info("Primary button");
            }
        }
    }
});

enter image description here


Solution

  • The centerVertical option is not implemented in the 4.x branch. You'll need to update Bootbox or add the Bootstrap class modal-dialog-centered yourself.

    There are few ways of accomplishing this in the 4.x branch. This might be the simplest way:

    // assign the result of bootbox.alert to a variable
    var d = bootbox.alert({
        message: "This is an alert, manually centered via <code>.modal-dialog-centered</code> on the vertical axis"
    });
    
    // `d` is a jQuery object, so we can chain additional function calls...
    d.find('.modal-dialog').addClass('modal-dialog-centered');
    

    jsFiddle: https://jsfiddle.net/3y26gpw9/1/

    If you want all of your modals centered, you can always adjust the source to append the relevant class to the template, here: https://github.com/makeusabrew/bootbox/blob/v4.x/bootbox.js#L39.