Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor instance already exists

I am using jquery dialogs to present forms (fetched via AJAX). On some forms I am using a CKEditor for the textareas. The editor displays fine on the first load.

When the user cancels the dialog, I am removing the contents so that they are loaded fresh on a later request. The issue is, once the dialog is reloaded, the CKEditor claims the editor already exists.

uncaught exception: [CKEDITOR.editor] The instance "textarea_name" already exists. 

The API includes a method for destroying existing editors, and I have seen people claiming this is a solution:

if (CKEDITOR.instances['textarea_name']) { CKEDITOR.instances['textarea_name'].destroy(); } CKEDITOR.replace('textarea_name'); 

This is not working for me, as I receive a new error instead:

TypeError: Result of expression 'i.contentWindow' [null] is not an object. 

This error seems to occur on the "destroy()" rather than the "replace()". Has anyone experienced this and found a different solution?

Is is possible to 're-render' the existing editor, rather than destroying and replacing it?

UPDATED Here is another question dealing with the same problem, but he has provided a downloadable test case.

like image 935
jackboberg Avatar asked Nov 25 '09 02:11

jackboberg


2 Answers

For this to work you need to pass boolean parameter true when destroying instance:

    var editor = CKEDITOR.instances[name];     if (editor) { editor.destroy(true); }     CKEDITOR.replace(name); 
like image 114
Tomas Kirda Avatar answered Oct 22 '22 06:10

Tomas Kirda


function loadEditor(id) {     var instance = CKEDITOR.instances[id];     if(instance)     {         CKEDITOR.remove(instance);     }     CKEDITOR.replace(id); } 
like image 44
Jim Avatar answered Oct 22 '22 04:10

Jim