views:

1533

answers:

3

I'm having a problem creating multiple instances of a CKEditor in a JQuery UI dialog. The dialog loads a remote form via AJAX, so the goal is to be able to close and reopen the dialog and have a new instance of the editor. With the default options, when reopening the dialog it gives an error saying that an editor with that name already exists. So I have tried several methods of destroying the editor instance and they all result in the same problem. When the editor is reloaded, the text area says null and the buttons don't function.

Currently I'm using this method of destroying the instance:

var instance = CKEDITOR.instances['test'];
if (instance) { CKEDITOR.remove(CKEDITOR.instances['test']); }

I recreated the issue with a couple of simple html files available for download here.

EDIT: I just tried using two remote files with a text area that has a different name and I have the same problem. When one dialog is opened and then closed, the other dialog has a "null" CKEditor when it is opened.

Also, apparently this is only a problem in Safari.

A: 

what I do:

var instance = CKEDITOR.instances['test'];
instance.destroy();
instance = null;
Scott Evernden
Just tried that, but I'm getting the same error. I think it must have something to do with JQueryUI/AJAX.
seth
A: 

seems like a duplicate:

http://stackoverflow.com/questions/1794219/ckeditor-instance-already-exists

ScottE
That was actually asked by my coworker, and wasn't resolved. I thought I would try re-asking the question with an attached example.
seth
Well, it certainly works for me - I'm creating and destroying these things many times in my application. I often don't know how many will be on the screen, nor what their ids will be. Works just fine.
ScottE
But have you tried using a jquery dialog box. I don't doubt that it works the way you have it.
seth
Why would that matter?
ScottE
I see your problem now. You have the script to load the CK editor right inside the html page that you're calling into the main page. That's your problem. Attach the editor in the callback function from the index page and you should be ok. Strangely enough it actually works on a PC in IE8 and FF3.5. Safari, no.
ScottE
It doesn't work even in the callback function, but you're right, it is only a problem on Safari. I should have noticed that sooner.
seth
My application that creates the CK editors in the .load callback function does work on Safari.
ScottE
A: 

I am new to CKEditor and I am having the same issue. What do you mean by the following?

Attach the editor in the callback function from the index page and you should be ok.

Trevor Orr
I think what he means is: The index page makes an AJAX call to the HTML page and inserts the HTML into the index page. You want the JS that loads the editor in the index page -- not in the HTML. The callback is the function that gets executed when the HTML is returned.
Dean
Also, I'm having this issue too.
Dean