2

I'm struggling to add dynamically a tinymce textarea.

I added a custom meta box which contains a button that should add a tinymce. As I'm on post/page, I guess I don't need to include any scripts because all is included due to the main tinymce editor.

I followed this help post but it doesn't work for me Dynamically textarea with TinyMce editor

My Script

function textarea_to_tinymce(id){
    if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
        tinyMCE.execCommand('mceAddControl', false, id);
    }
}

jQuery('.button').click(function() {    
    jQuery("#text-container").append('<textarea class="content" id="test" name="test"></textarea>');
    textarea_to_tinymce("test");
    return false;
});

I'm currently have no idea what I'm doing wrong. The textarea just don't transform to a tinymce. In fact the tinyMCE.execCommand('mceAddControl', false, id); just does not have any impact and I don't know why. Does anyone have some help for me? Thanks

3
  • We also have no idea what you are doing wrong. The main reason why: You didn't provide any error or where you are stuck.
    – kaiser
    Commented Dec 12, 2014 at 13:17
  • Thanks for our comment. the textarea just don't transform to a tinymce. In fact the tinyMCE.execCommand('mceAddControl', false, id); just does not have any impact and I don't know why.
    – Benmay
    Commented Dec 12, 2014 at 13:21
  • As an edit/update to your question, please.
    – kaiser
    Commented Dec 12, 2014 at 13:21

1 Answer 1

1

This works for me:

tinyMCE.execCommand("mceAddEditor", false, id);
tinyMCE.execCommand('mceAddControl', false, id);
1
  • 1
    Just my problem is why the editor tools (Add Media, Visual & Text Options) are not showing up.
    – RicardO
    Commented Aug 8, 2015 at 17:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.