Search code examples
javascriptjqueryhtmltinymce

How to disable tinymce after it is fully initialized?


Right now, I'm using this line of code to disable tinyMCE

tinyMCE.get('tinymce_id').getBody().setAttribute('contenteditable', false);

However, it doesn't seem to be disabled on initialization. Only when I select the radio buttons then it will be disabled.

How do I disable specific tinyMCE editor after it initializes? If possible, I would like an answer which works for IE8 too. Thanks in advance!


JQuery :

 require(['tinymce'],function(){

            var disableInputs = function(){
                if($('input[name=type]:checked').val()==1){
                    tinyMCE.get('newsletter_message').getBody().setAttribute('contenteditable', false);
                    tinyMCE.get('category_message').getBody().setAttribute('contenteditable', true);
                }else{
                    tinyMCE.get('newsletter_message').getBody().setAttribute('contenteditable', true);
                    tinyMCE.get('category_message').getBody().setAttribute('contenteditable', false);
                }
            };
            $('input[name=type]').on('click',function(){
                disableInputs();
            });
            disableInputs();

        });

HTML :

<input type="radio" value=1 name=type/>
<div id="newsletter"> tinymce with id of newsletter_message initializes here... </div>

<input type="radio" value=0 name=type/>
<div id="category"> tinymce with id of category_message initializes here... </div>

Solution

  • in V6:

    tinymce.activeEditor.hide()
    

    and to turn it on again

    tinymce.activeEditor.show()
    

    https://www.tiny.cloud/docs/tinymce/6/apis/tinymce.editor/#hide