Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TinyMCE textarea can't edit

Here is the problem. In my php submission page, I have a form with multiple fields including a textarea which is currently using TinyMCE and I also have an option for duplicating existing form. The thing is I can't edit the 2nd editor that was duplicated but the editor appear in textarea place. However I can edit and save 1st editor. I am not sure if its a bug or just me doing something wrong? I tried to update TinyMCE as well but didn't work.. any idea?

function initTinyMCE() {
   tinyMCE.init({
       mode : "textareas", //mode : "exact", elements : "mytextarea"
       theme : "simple"
   });
}
initTinyMCE();


$(document).ready( function(){
    $('a#addmore').live('click', function(){

         //*clone the existing form and inserting form here*
         initTinyMCE(); 
    });

    $('a#toSubmit').live( 'click', function() {
      tinyMCE.triggerSave();
      $('.editwork-form').submit();
});

});
like image 675
zaw Avatar asked Aug 22 '12 10:08

zaw


People also ask

How do I get content from TinyMCE textarea?

You can do this using the getContent() API method. Let's say you have initialized the editor on a textarea with id=”myTextarea”. This will return the content in the editor marked up as HTML.

How do you make TinyMCE editor readonly?

Use the checkbox to toggle between the "design" and "readonly" modes.

How do I reinitialize TinyMCE?

Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.

How do you enter a source code on TinyMCE?

On the menu bar, open Tools > Source code. Click the Source code toolbar button.


2 Answers

I can't seem to get .clone() to work, nothing in the debug console either. However, my working solution is as follows, maybe this helps?

initTinyMCE();

$("#append").live("click", function() {
    var ta_count = $("textarea").length;

    var elem = document.createElement("textarea");
    $(elem).attr("id", ta_count.toString());
    $(elem).appendTo("#ta_container");

    initTinyMCE();
});

function initTinyMCE() {
    tinyMCE.init({
        mode: "textareas",
        theme: "simple",
        theme_advanced_path: false
    });
}​

Instead of .clone()ing the element, I'm just creating a new textarea and appending it to the container (using the count of all textareas on the page as it's ID to make it unique), then re-calling the tinyMCE initialiser.

Example jsFiddle

like image 188
Paul Aldred-Bann Avatar answered Oct 18 '22 09:10

Paul Aldred-Bann


Make sure your textareas have different ids, otherwise there won't be a second editor instance! This is a crucial thing when creating tinymce editor instances.

like image 38
Thariama Avatar answered Oct 18 '22 09:10

Thariama