Luke
Luke

Reputation: 119

How to make a read-only tinyMCE editor writetable again

I want to make some TinyMCE text editors on a page temporarily readonly.

I understand this technically possible using:

tinymce.get('id').getBody().setAttribute('contenteditable', false);

then we can re-enable them with:

tinymce.get('id').getBody().setAttribute('contenteditable', true);

However, I've found that using:

tinymce.get('id').setMode('readonly');

suits the needs of my project better when disabling as it makes the the whole textarea appear and become disabled.

My problem is that I can't then remove the setMode('readonly'), or find out what I should "re-set" the mode to.

I've tried:

tinymce.get('id').setMode('readonly', 0);

for example. But nothing seems to work.

TIA.

Upvotes: 0

Views: 2177

Answers (1)

Michael Fromin
Michael Fromin

Reputation: 13746

When you use the setMode() API you can pass one of two string values to switch the mode:

  • readonly
  • design

For example: tinymce.get('content').setMode('design');. Here is a running example of toggling between the modes:

http://fiddle.tinymce.com/Gdhaab

The documentation for this can be found here: https://www.tiny.cloud/docs/api/tinymce/tinymce.editormode/#set

Upvotes: 1

Related Questions