DoublePudge
DoublePudge

Reputation: 95

Tinymce how to call init on a new added textarea?

I'am using tinymce, so the first time I call

tinymce.init({

   // initiation code, that makes my textarea a tinymce textarea

})

After I add a new textarea and call again tinymce.init - it won't work. How can I convert a newly added textarea into a tinymce textarea?

Upvotes: 1

Views: 1982

Answers (3)

Aivils Štoss
Aivils Štoss

Reputation: 908

After tinymce.init({}); you need to run this code:

tinyMCE.execCommand("mceAddControl", true, textAreaID);

However it does not work under firefox. Litle modification:

setTimeout( function(){
   tinyMCE.execCommand('mceAddControl', true, textAreaID );
}, 100);

Link to this

Upvotes: 2

Pterpatty
Pterpatty

Reputation: 19

Try this, with added functions

<script>
    tinymce.init({
        selector: "textarea.tiny-mce-init",
        menubar: false,
        width: '100%',
        height: 200,
        resize: false,
        plugins: [
             "code advlist autolink link image lists charmap print preview hr pagebreak spellchecker",
             "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
             "save table contextmenu directionality emoticons template paste jbimages"
        ],
        toolbar: "code | undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | forecolor backcolor| jbimages | pastetext | fontselect | fontsizeselect | preview ", 
        // ===========================================
        // SET RELATIVE_URLS to FALSE (This is required for images to display properly)
        // ===========================================
        relative_urls: false
     }); 
    </script>

and you should call the class in the input type textarea

<textarea name="sample" class="tiny-mce-init"></textarea>

Upvotes: 0

Jassi
Jassi

Reputation: 541

I don't think you need to call tinymce.init again and again for more than one textarea tag in the same page. Try below code and let me know it works.

tinymce.init({
    selector: "textarea",

   // initiation code, that makes my textarea a tinymce textarea

})

It will take care of all textarea tags encountered in the present page.

Upvotes: 0

Related Questions