Reputation: 3001
I'd like to switch a form between enabled / disabled states. The form includes a formatted text field implemented using a tinyMCE 4.0 editor. I can set this to be readonly on load as follows
tinyMCE.on('AddEditor', function(addEditorEvent) {
addEditorEvent.editor.settings.readonly = true;
});
but subsequently calling
tinyMCE.get('my-editor').settings.readonly = false;
has no effect. Is there a way to trigger the editor to re-initialize or some other way of getting it to pick up this change in state?
Upvotes: 2
Views: 3402
Reputation: 21666
<script type="text/javascript">
tinymce.init({ selector: 'textarea' });
var is_disabled = false;
function enable_disable(btn) {
is_disabled = !is_disabled;
tinymce.activeEditor.getBody().setAttribute('contenteditable', !is_disabled);
btn.value = is_disabled ? "Enable" : "Disable";
}
</script>
<textarea>Your content here.</textarea>
<input type="button" value="Disable" onclick = "enable_disable(this)" />
Upvotes: 0