All documentation ↓← All docs

editor.getReadOnly()

Returns whether the editor is currently read-only. Use it to reflect the editing state in your own UI — for example to show a lock icon, or to decide whether a “save” button should be enabled — and as the current value when toggling the mode.

Syntax

editor.getReadOnly()

Parameters

None.

Returns

A boolean: true when the editor is read-only, false when it is editable.

Behavior notes

  • It reports the current mode only. The value flips when you call setReadOnly(); there is no separate flag to keep in sync.
  • Always a boolean. The result is a real true/false, safe to use directly in conditionals.
  • Pair it with setReadOnly to toggle. Reading the current value and passing its inverse is the standard toggle pattern.

Example usage

Toggle read-only mode from a button, using the current value:

Code example
var editor1 = new RichTextEditor("#div_editor1");
document.getElementById("btn_lock").onclick = function () {
    editor1.setReadOnly(!editor1.getReadOnly());
};

Only allow saving when the editor is editable:

Code example
if (!editor1.getReadOnly()) {
    save(editor1.getHTMLCode());
}

Related

Calling editor.getReadOnly() from your app

editor.getReadOnly() belongs to the editor instance. Every integration below works the same way: keep the object that new RichTextEditor(...) returns, and call it on that object.

Plain JavaScript

Code example
var editor1 = new RichTextEditor("#div_editor1");
// The constructor is synchronous: the editor is ready on the next line.
editor1.getReadOnly();

React and Next.js

Code example
// editorRef is filled by the RichTextEditor wrapper from the React guides.
const editorRef = useRef(null);

function onClick() {
  editorRef.current?.getReadOnly();
}

return <RichTextEditor editorRef={editorRef} />;

In Vue and Angular, the wrapper components in the guides keep the instance in a component variable (editor), so the call is the same. See the React, Vue and Angular pages, or download a tested project from the guides.

If the editor is undefined

  • The call ran before the component mounted. Call it from an event handler or after the mount effect has run.
  • In React development mode, Strict Mode mounts, unmounts and mounts again, so the wrapper sets editorRef.current to null in between. Use editorRef.current?. rather than storing the instance elsewhere.
  • The editor was destroyed (editor.destroy()) when its component unmounted.

All methods: method reference · all events: event reference.