Daniel
Daniel

Reputation: 1026

Replace config attribute in CKEditor 4.10: a is undefined

Having a instance of CKEditor in some proprietary third party app, I want to replace some config parameters for customization purpose. For example, some toolbar buttons are removed by refault, I want to make all visible.

I tried different things like

var instance = CKEDITOR.instances['editor2']
instance.config.removeButtons = ""
instance.destroy()
CKEDITOR.replace('editor2')

which I found here, but got always the following error:

TypeError: a is undefined

Found some SO queststions where this is related to a leading # in the Id, but i dont have it and the instance exists when looking into the instances with browser developer tools:

> CKEDITOR.instances
Object { editor1: {…}, editor2: {…} }

Also tried the following Id of the object instead of editor2

> CKEDITOR.instances.editor2.id
"cke_54"

Or use replace:

CKEDITOR.replace('editor2', {removeButtons: ''})

But all of this doesn't work too, I always get the same error that a is undefined. The editor itself works and doesn't throw any errors in the browser console.

Upvotes: 1

Views: 249

Answers (1)

maestrojed
maestrojed

Reputation: 345

I had this same error:

TypeError: a is undefined

I traced my issue to the element not being found. Specifically for me, my document had not fully loaded when my JS code, similar to yours, was run.

I would investigate two things:

  1. Ensure there is an element in your document with the ID='editor2'.
  2. Don't run your JS until the document is ready. Do this by wrapping it in $( document ).ready(). Example:

    $( document ).ready(function() { var instance = CKEDITOR.instances['editor2'] instance.config.removeButtons = "" instance.destroy() CKEDITOR.replace('editor2') });

Upvotes: 1

Related Questions