admin管理员组文章数量:1435859
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 badges1 Answer
Reset to default 6Solved 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 :-)
本文标签: javascriptHow to start TinyMCE with contenteditablefalseStack Overflow
版权声明:本文标题:javascript - How to start TinyMCE with contenteditable:false - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745668200a2669408.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论