Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Populate the tinymce textarea with content at OnReady?

Here is my tinymce code . I am populating the tinymce textarea with content 'Cust Details' at on ready event. But tinyMCE.activeEditor evaluates as null even after appending the text area with tinymce

 $(function() {
            appendTinyMCE();
          function appendTinyMCE(){
            tinyMCE.init({

            // General options
            mode : "textareas",
            theme : "advanced",
            plugins : "preview",
            // Theme options
            theme_advanced_buttons1 : "forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,formatselect,fontselect,fontsizeselect,sub,sup,|,bold,italic,underline,strikethrough",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            width : "640",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true

        });}



      alert("tinyMCE.activeEditor"+tinyMCE.activeEditor);// inyMCE.activeEditor is coming as  null. Not getting why
      if(tinyMCE!=null && tinyMCE.activeEditor!=null)
          {
          tinyMCE.activeEditor.setContent('Cust Details');
          }


    });

Please let me know how i can populated the tiny mce text area on ready event?

like image 697
M Sach Avatar asked Feb 19 '23 17:02

M Sach


1 Answers

I had the same issue a while back...

Try setting the the text-area content from the init_instance_callback param in init options:

init_instance_callback : function() {                                                   
     tinyMCE.activeEditor.setContent('Cust Details');
}

applying this to your code snippet should look something like:

$(function() {
            appendTinyMCE();
          function appendTinyMCE(){
            tinyMCE.init({

            // General options
            mode : "textareas",
            theme : "advanced",
            plugins : "preview",
            // Theme options
            theme_advanced_buttons1 : "forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,formatselect,fontselect,fontsizeselect,sub,sup,|,bold,italic,underline,strikethrough",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            width : "640",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_statusbar_location : "bottom",
            theme_advanced_resizing : true,
            init_instance_callback : function() { tinyMCE.activeEditor.setContent('Cust Details');}

        });}
    });
like image 119
adamb Avatar answered Feb 27 '23 10:02

adamb