javascript - Init function for bootbox to use some code after showing dialog - Stack Overflow

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

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.

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.

Share Improve this question asked Oct 27, 2015 at 7:57 user3142695user3142695 17.4k55 gold badges200 silver badges375 bronze badges 4
  • 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 pletely. – Rory McCrossan Commented Oct 27, 2015 at 8:01
  • what would you remend? – user3142695 Commented Oct 27, 2015 at 8:02
  • Have a search, there are literally hundreds of dialog libraries. – Rory McCrossan Commented Oct 27, 2015 at 8:02
  • @RoryMcCrossan Well, bootbox is simply a wrapper around Bootstrap's modals, so it has those events: getbootstrap./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. Commented Oct 29, 2015 at 4:42
Add a ment  | 

1 Answer 1

Reset to default 7

Just add a show event:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745174007a4615099.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信