Note that there are some explanatory texts on larger screens.

plurals
  1. POsetReadOnly causes error when called on instanceReady of CKEditor
    primarykey
    data
    text
    <p>I'm trying to set my CKEditor instance to be "readOnly" after the instance has fully loaded but I'm getting a Javascript error: <code>Cannot call method 'setReadOnly' of null</code>. When I dig into it, the error is coming from this line in the ckeditor.js, within the <code>editor.setReadOnly</code> method: <code>this.editable().setReadOnly(a);</code> That means that the editor exists, but the <code>editable</code> method/attribute (on the CKEditor instance) does not. </p> <p>Below is my code, and I'll explain it a little. My app is a combination of GWT and Backbone. The CKEditor itself is created by the Backbone code but the parent element is in GWT so that's where I initiate the <code>setEnabled</code> action.</p> <pre><code>private native void setEnabledOnLoad(boolean enabled, String id) /*-{ CKEDITOR.on("instanceReady", function(evt) { if(evt.editor.name === id) { Namespace.trigger(Namespace.Events.SET_ENABLED, enabled); } }); }-*/; setEnabled: function(enabled) { this.editor.setReadOnly(!enabled); if(enabled){ this.editor.focusManager.focus(); } else { this.editor.focusManager.blur(); } } </code></pre> <p>The Backbone class has a listener for <code>Namespace.Events.SET_ENABLED</code> that triggers <code>setEnabled</code>.</p> <p>Is there another CKEditor event that I should listen for? There doesn't appear to be an <code>instanceReady</code> event on <code>editable</code>. What am I missing?</p> <p><strong>EDIT</strong><br> <code>this.editor</code> is created in the Backbone class <code>render</code> function like this: </p> <pre><code>this.editor = CKEDITOR.replace(this.$(this.id)[0], config); </code></pre> <p>The reason I don't add the <code>instanceReady</code> listener right after it's created is because the function <code>setEnabledOnLoad</code> is called in GWT before the instance has been fully initialized. This is a result of having the code in two places. GWT has said "ok, create the instance" but Backbone hasn't finished by the time GWT goes to the next line of code and wants to set it enabled/disabled.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload