Search code examples
javascripthtmltwitter-bootstrapbootbox

Bootbox - how to dynamically change message content?


I was wondering if there is a way to dinamically update the content of a bootbox modal.

Example

bootbox.dialog({
        message: "Hi there",
        title: "My title",
        buttons: {
            main: {
                label: "dismiss",
                className: "btn-primary",
            }
        }
    });


    newMessage = "this is a new message"

Is there a way to replace that "Hi there" with the new string newMessage?

Thanks for any help or suggestion


Solution

  • Simple! Create a generic function:

    function bootBoxModal(title, message, type) {
        bootbox.dialog({
            message: message,
            title: title,
            alertType: type,
            buttons: {
                main: {
                    label: 'Fechar', className: 'btn-default'}
            }
        });
    }
    

    Call the function now:

    bootBoxModal("Title message", 
                 "Content your message", 
                 "type [alert,danger,warning,success]");