2

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.

user3142695
  • 15,844
  • 47
  • 176
  • 332
  • The issue is because `init()` is called *before* the UI of the dialog is in the DOM. This plugin seems *extremely* poor in the fact that it doesn't have any events you can hook to when content is displayed/hidden. For that reason I would suggest you use a different plugin completely. – Rory McCrossan Oct 27 '15 at 08:01
  • what would you recommend? – user3142695 Oct 27 '15 at 08:02
  • Have a search, there are literally hundreds of dialog libraries. – Rory McCrossan Oct 27 '15 at 08:02
  • @RoryMcCrossan Well, bootbox is simply a wrapper around Bootstrap's modals, so it has those events: http://getbootstrap.com/javascript/#modals-events. Or, were you looking for events for when bootbox is generating it's own content for it's alert, confirm, and prompt helpers? – Tieson T. Oct 29 '15 at 04:42

1 Answers1

6

Just add a show event:

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