9
votes

I'm trying to remove tinyMCE from a specific textarea that I have created earlier but the following command kept on producing "undefined" error (checked using firebug console):

tinyMCE.execCommand('mceFocus', false, 'textarea-plainText');
tinyMCE.execCommand('mceRemoveControl', false, 'textarea-plainText')

I have initialized the TinyMCE for that particular text area using jQuery:

$('textarea#textarea-plainText').tinymce({
                script_url : '<?php echo base_url(); ?>/assets/js/tinymce/tinymce.min.js',
                oninit: function() {
                            $("textarea#textarea-plainText").tinymce().setContent("");
                            $("textarea#textarea-plainText").tinymce().setContent(noteSecContent.html[0].notesec_content);
                        }
            });

I have also try to add tinyMCE using the following command but it also return undefined although I have a textarea with "textarea-plainText" ID:

$.getScript('<?php echo base_url(); ?>assets/js/tinymce/tinymce.min.js', function() {
            window.tinymce.dom.Event.domLoaded = true;
            tinyMCE.init({
                mode: 'none'
            });
            tinyMCE.execCommand('mceAddControl', false, 'textarea-plainText');
        });

In short, I can only initialize either using the jquery method or exact method. But not using tinyMCE.execCommand. Somehow the "exeCommand" command just wont work.

HTML for the textarea:

<div id="plainTextModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="plainTextLabel" aria-hidden="true">
  <div class="modal-body">
   <textarea id='textarea-plainText'></textarea>
  </div>
  <div class="modal-footer">
    <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <a href="" id="confirm-delete-note-section" class="btn btn-primary">Save</a>
    <a href="" id="confirm-delete-note-section" class="btn btn-info">Save &amp; Close</a>
  </div>
</div>

It's a modal, so it is initially hidden until the modal is called.

I'm using TinyMCE 4.0b1 by the way.

1
i am not sure, but can you try to use id swithout '-' and see if that helps? - Thariama
Yes. I tried with IDs without '-' and it still produces the same error - svenbit
can you create a tinymce fiddle or other kind of live example? - Thariama
Okay sure. I tried with the very basic implementation but the textarea is not transformed into TinyMCE as well: jsfiddle.net/6cPaC/1 Did I miss something here? Or is the command "execCommand" still works for tinyMCE 4? - svenbit
I guess similar init method works in version 3.5: fiddle.tinymce.com/tcdaab - svenbit

1 Answers

15
votes

You get undefined because in 4.x they removed mceRemoveControl and mceAddControl (I'm not sure about mceFocus) so use mceAddEditor and mceRemoveEditor instead.

Because these codes did the same stuff they removed mceRemoveControl and mceAddControl in the cleanup.

And also don't forget you need to use tinymce in lower case from now.