Log in or register to post comments
Last post
bvi
bvi's picture
Joined: 14/09/2009
Posts: 2
CKEditor instance disappears after AJAX form submit
Issue:
On an AJAX form submit, the correct value of the CKEditor is succesully posted and inserted into a database. However, after the first submission the editor completely disappears (including the original text field).

Background:
* The CKEditor instance is initated by the CKEDITOR.replace method of an existing text field.
* Tried using the CKEDITOR.appendTo approach to dynamically create the editor - however the same issue occurs.
* The text field is located in a seperate page which is pulled into the main page via AJAX.
* The updated contents of the CKEditor are obtained via the following snippet:
for(var name in CKEDITOR.instances)
         CKEDITOR.instances[name].updateElement();


My guess would be that the CKEditor instance needs to be destroyed and recreated after submission? However, I have searched, read and experimented extensively and have not been able to rectify the issue.

Can anyone please provide some help with this?

Thanks in advance.
cferretti's picture
Joined: 14/09/2009
Posts: 1
Re: CKEditor instance disappears after AJAX form submit
Fist, let me apologize for posting without an answer.

I'm having almost the same problem here, but i believe the cause is the same. Mine is a form loaded with xajax, first time the form is replaced successfully, but when try to reload the form, the textarea vanishes but isnt replaced by the ckeditor. I didn't even get to submit anything, just change pages, when i get back, it's gone... This happens when i try with replace. The appendTo loads everytime, but i didnt figure yet how to get its value and get it sent hitting the form submit by post method along with the other fields as if it was a normal field. :oops:

I guess we are more or less in the same boat here.. anyone else can give some help?
bvi
bvi's picture
Joined: 14/09/2009
Posts: 2
Re: CKEditor instance disappears after AJAX form submit
If anyone is interested in a solution that worked for this issue:

http://cksource.com/forums/viewtopic.php?f=11&t=15499&p=39483&hilit=destroy+ckeditor#p39483

Solved the issue using an example from the link above:

After a succesful form submission this piece of javascript solved the issue:
delete CKEDITOR.instances[ 'editor name' ];


It appears that you are supposed to use the destroy function: http://docs.fckeditor.net/ckeditor_api/symbols/CKEDITOR.editor.html#destroy

However I could not get it to work. If anyone can offer more instruction than the documentation it would be helpful.
dogbreath's picture
Joined: 18/09/2009
Posts: 1
Re: CKEditor instance disappears after AJAX form submit
Here's what worked for my Ajax form:

<form id='myForm' ... >
<textarea id='myTextArea'></textarea>
<script type='text/javascript'>
try { CKEDITOR.replace('myTextArea'); } catch(e){}
</script>

<input type="submit" name="submit" value="Save" onclick="document.getElementById('myTextArea').value=CKEDITOR.instances.myTextArea.getData(); CKEDITOR.instances.myTextArea.destroy()" /> 
</form>
garry.yao's picture
Joined: 03/01/2009
Posts: 170
Re: CKEditor instance disappears after AJAX form submit
@BVI It's better to provide an reduced example page to help us understand your issue.
adamp's picture
Joined: 28/10/2009
Posts: 1
Re: CKEditor instance disappears after AJAX form submit
Hi guys,

The solution that worked for me was as follows:

if (CKEDITOR.instances['Field1']) {
CKEDITOR.remove(CKEDITOR.instances['Field1']);
}

CKEDITOR.replace( 'Field1');

Hope this helps,
Adam