Reputation: 7688
How can I toggle the readonly
state in an initialized tinyMCE container?
Whilst the tinyMCE is initialised in a common javascript file, the option I want to change is specific to the logic of an individual page, and changes based on user's input via a checkbox.
This are some of the things I tried and all resulted in failure: http://pastebin.com/JEn2fyE6
Upvotes: 4
Views: 7923
Reputation: 21
Please check this code
setTimeout(function () {
for (var i = 0; i < tinymce.editors.length; i++) {
tinymce.editors[i].getBody().setAttribute('contenteditable', false);
};
},1000);
Upvotes: 2
Reputation: 7688
I just managed to do it this way:
Having the textarea
set with id intro
I do this
if($('.disabled_check').is(':checked')) {
$('#intro_ifr').contents().find('body').attr('contenteditable', false);
}
Upvotes: 6
Reputation: 50832
You may set this setting after init using
tinymce.get('my_editor_id').settings.readonly = false;
But this won't influence the editor behaviour in the way you desire because the relevant part were processed while initialization.
The working approch here is what JP Hellemons already stated.
Upvotes: 0
Reputation: 6057
So you want to set this option http://www.tinymce.com/wiki.php/Configuration:readonly after the init. according to this thread: http://www.tinymce.com/forum/viewtopic.php?id=15488 it can not be done according to the folks of the tinymce forum.
This S.O. answer seems to work: Set TinyMCE Editor Param after Initialized
tinymce.activeEditor.getBody().setAttribute('contenteditable', false);
If it does not, this topic has a workaround: http://forum.morfik.com/posts/21058 create two instances of tinymce one readonly, one normal and only display the desired one.
Upvotes: 3