Eventhough getData() doesn't return the new input, getDirty() correctly indicates that the contents of the editor changed since initialization, which makes it even weirder.
EDIT 2: Using the Safari Activity Log I observed that each time I perform the AJAX call, the CKEditor resources were being loaded again and again on top of the ones that were already there. Could my problem be caused by the fact that my original form elements still stay present somewhere in the DOM even after I inject new ones into the same div ? Or is that just a harmless side-effect of using AJAX ?
EDIT 3: I think I was able to trace down the problem to the instance not being destroyed. This doesn't look like intended behavior to me.
edinstance.destroy(); alert(edinstance.getData()); //Still returns the old contents of the editor
And the reason this is causing a problem seems to be because the instance is not being retrieved from the textarea the second time around.
edinstance = null; //Tried setting the instance variable to null before getting the new instance from the textarea edinstance = $('textarea#contents').ckeditorGet(); //This causes an error "edinstance is null"
This leads me to believe that even after replacing the innerHTML that includes the textarea, it is still available to CKEditor somehow. Since I'm using the id of the textarea, this could explain my problems.
EDIT 4: Ok this is beyond me... To make sure the editor was linked to the latest textarea I gave it a random id. I have verified that the instance is actually current, I can use every method and access any property EXCEPT FOR getData() even getSnapshot correctly returns all recent input while getData() doesn't, how is that even possible. If I use setData(), getData will start returning whatever I set, but it doesn't change the contents of the actual editor on the screen.
Background:
I have a form that is injected into the page with AJAX.
The form contains a textarea contents and it may already contain some content set in the PHP backend.
"<textarea id=\"contents\" class=\"article\">" . $articleContent->getBody() . "</textarea>"
I have a global javascript variable edinstance that I use to hold the current instance of CKEditor.
After the form is loaded I check if the global variable already contains an instance, if this is the case I destroy it. This is necessary to avoid conflicts because the form may be closed and reloaded several times without refreshing the full page.
I attach a new instance of CKEditor to the textarea and place it in the global
function attachEditor() { if(typeof edinstance != "undefined") { edinstance.destroy(); //alert('editor destroyed'); } $('textarea#contents').ckeditor(); edinstance = $('textarea#contents').ckeditorGet(); }Scenario:
Re: getData() returns old contents after the first time (PHP
Could you publish a test case online?
Re: getData() returns old contents after the first time (PHP
While the issue isn't that urgent, I was hoping this would be a common problem due to some beginner oversight or something.
Using the Safari Activity Log I observed that each time I perform the AJAX call, the CKEditor resources were being loaded again and again on top of the ones that were already there. Could my problem be caused by the fact that my original form elements still stay present somewhere in the DOM even after I inject new ones into the same div ? Or is that just a harmless side-effect of using AJAX ?
Re: getData() returns old contents after the first time (PHP
Use .destroy(true) instead, that will do the cleanup correctly.
Hope this saves some time for someone (I've wasted a few hours searching for the same issue, little bit later found the answer there: http://dev.ckeditor.com/ticket/8226).
That's one really annoying problem, yet still not patched in the public release...
Re: getData() returns old contents after the first time (PHP
Oh, yes, here you are right, this problem makes me mad!!! Hopefuly smn will find the solution soon, otherwise I ...
Re: getData() returns old contents after the first time (PHP
so anyone who is getting frustrated on this issue just get the iframe data instead of using getData()
sample code
var iframe=$("iframe",parentnode);
var value=$("body",iframe.contents()).html();