Search code examples
javascriptjqueryredactorbootbox

Init function for bootbox to use some code after showing dialog


I want to display a textarea-element with bootbox. This textarea should be used with a WYSIWYG-editor, which will be initialized by

$('#editor').redactor();

So I want to add this in the moment the textarea is displayed. I tried this:

bootbox.dialog({
    title: "Title",
    message: '<textarea id="editor"></textarea>',
    init: function () {
        $('#editor').redactor();
    }
});

But this seems to be wrong.


Solution

  • Just add a show event:

    var box = bootbox.dialog({
        title: "Title",
        message: '<textarea id="editor"></textarea>'
    });
    box.bind('shown.bs.modal', function(){
        $("#editor").redactor();
    });