javascript - How to start TinyMCE with contenteditable:false - Stack Overflow

I'm struggling with building a TinyMCE textarea input field which should be toggled from enabledd

I'm struggling with building a TinyMCE textarea input field which should be toggled from enabled/disabled depending on the state of other input fields. So far I've got the following working to toggle it:

var mceInstance = tinymce.get(TargetElementId);
mceInstance.getBody().setAttribute('contenteditable',false);

By toggling the 'contenteditable' parameter like this I can easily make the textarea disabled or not, so far so good.

The last problem I have to tackle, is that the textarea should be disabled upon initial loading, and it seems the 'contenteditable' parameter can't be passed as an tinyMCE.init() parameter... There is a 'readonly' paremeter which can be passed with tinyMCE.init(), but that one can't be toggled at a later time...

Any ideas on how to acplish this?

I'm struggling with building a TinyMCE textarea input field which should be toggled from enabled/disabled depending on the state of other input fields. So far I've got the following working to toggle it:

var mceInstance = tinymce.get(TargetElementId);
mceInstance.getBody().setAttribute('contenteditable',false);

By toggling the 'contenteditable' parameter like this I can easily make the textarea disabled or not, so far so good.

The last problem I have to tackle, is that the textarea should be disabled upon initial loading, and it seems the 'contenteditable' parameter can't be passed as an tinyMCE.init() parameter... There is a 'readonly' paremeter which can be passed with tinyMCE.init(), but that one can't be toggled at a later time...

Any ideas on how to acplish this?

Share Improve this question asked Dec 24, 2013 at 15:32 AlexAlex 1,0502 gold badges18 silver badges35 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Solved it!

I found that by passing init_instance_callback with the TinyMCE init code, I could run the same code as used in my 'toggle' function. So you can pass this in the TinyMCE init part if you want this:

init_instance_callback : function(editor)
{
    if(document.getElementById(editor.id).hasAttribute('disabled'))
    {
        editor.getBody().setAttribute('contenteditable',false);
        editor.getBody().style.backgroundColor = "grey";
    }
}

The above code will look at the specified instance, if the originating HTML element (textarea in my case) has the 'disabled' attribute, it will set the 'contenteditable' parameters to false.

I hope this is useful to someone else, I know I was happy when I cracked it :-)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745668201a4639243.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信