I've been struggling with this for about an hour and could find anything on the web.
When following code is performed, the second call of getData returns an empty string. Am I doing sht wrong or is this a bug (perhaps some timing prob?)? The code is from the API-sample. Any workarounds in case it's a bug?
Thanks for any help,
flo
Edit: This seems to be a problem within FF. Safari shows the changed content.
function SetContents()
{
// Get the editor instance that we want to interact with.
var oEditor = CKEDITOR.instances.editor1 ;
var value = document.getElementById( 'plainArea' ).value ;
// Set the editor contents (replace the actual one).
alert("before: " + oEditor.getData());
oEditor.setData( value ) ;
alert("after: " + oEditor.getData());
}
When following code is performed, the second call of getData returns an empty string. Am I doing sht wrong or is this a bug (perhaps some timing prob?)? The code is from the API-sample. Any workarounds in case it's a bug?
Thanks for any help,
flo
Edit: This seems to be a problem within FF. Safari shows the changed content.
function SetContents()
{
// Get the editor instance that we want to interact with.
var oEditor = CKEDITOR.instances.editor1 ;
var value = document.getElementById( 'plainArea' ).value ;
// Set the editor contents (replace the actual one).
alert("before: " + oEditor.getData());
oEditor.setData( value ) ;
alert("after: " + oEditor.getData());
}
Re: Strange getData setData behaviour
alert (value)
my hunch here is that the problem is with the following statement
this may work for Safari, but not FF or other browser. Remember, every browser is different, so you'll have to code around the specific browser
something like
Re: Strange getData setData behaviour
Hey,
).
thanks for your reply!
This is just the API-Sample as written. The setData part does work well. But if you call getData immediately after setData it is always empty in FF.
I did test this on IE8:
Details zum Fehler auf der Webseite
Benutzer-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)
Zeitstempel: Wed, 2 Dec 2009 21:15:38 UTC
Meldung: 'this.$.innerHTML' ist Null oder kein Objekt
Zeile: 15
Zeichen: 656
Code: 0
URI: file://vmware-host/Shared%20Folders/My% ... keditor.js
and FF Win that behaves same to FF Mac. My first thought was that it's some sort of timing problem (or my bloated FF
My aim was to manipulate the HTML code on submit. I managed it in the meantime by some crappy hack.
Best regards,
flo
Re: Strange getData setData behaviour
Re: Strange getData setData behaviour
But what do I do if i need to update replaced element just after setData?
This is really strange... Such behavior doesn't make any sense.
Re: Strange getData setData behaviour
Why don't you use the data that you have used in the call to setData?
Re: Strange getData setData behaviour
Well, for a couple of reasons:
1. Maybe the data that was set is local/private to an external class that we don't have access to
2. Tracking purposes
3. copy the data from one editor to another
4.. I mean the list could go on and on....
Re: Strange getData setData behaviour
Are you trying to fool me or what???

the value of the data is in the f*cking call to setData() so he already knows it!!!
I don't care what you are trying to do but as soon as you are calling editor.setData(value) you already know that the new value of the editor when the browser finishes parsing, loading, etc.. will be "value" so your list is just senseless talk.
If you really want the data after it has been loaded, then learn how to use the events and you'll know how to get it. I'm not gonna bother to write it because that would mean another stream of posts asking basic questions and claiming that it should be done some other way because he likes it more that way.
Re: Strange getData setData behaviour
Simply not worth my time to step down to your level....
“Real knowledge is to know the extent of one's ignorance.”
Re: Strange getData setData behaviour
thanks for the discussion so far although it escalated for no reason.
It's good to know that setData is asynchronous. As I wrote I wanted to manipulate the contents of the editor just on submitting the form what resulted in an empty post because setData wasn't performed "in time".
Because you have a callback in setData you could do sth like this:
Maybe it should be documented that this call is asynchronous.
Peace,
flo
Re: Strange getData setData behaviour
heh
First of all. Lets say I'm using setData('123'). And I'm using the same data for updating the element manually. In this case datas will be different, cuz after a delay data in element will become somthing like '<p>123</p>'.
Ok. This can be avoided with data preformatting (not very reliable actually) or updating a value in a callback. But in any case this is not something what i would expect to do. Logically it is right to be able to do getData just after the data was set.
This is the first point.
Next. The problem is with external libraries compatibility. Say I'm using ExtJS. And I'm extending some form classes with CKEditor functionality. The reason I do this is to be able to use editor just as the normal field and to be able set, get and reset data. The main problem is with reset. There is a part of code in ExtJS that save the original value like this
From this value the data will be reset.
In setValue() I just use editor.setData(). And in getValue() I do updating of an element and getting the data from it. Of course the element is updated with an empty string.
I'm sure, you can say that it is not CKEditor problem, and it is the author of code mentioned above who made a mistake. But I wont agree with this. CKEditor is an applied tool. And it was developed to be used with external libraries mostly. Such problems with making setData() async should be predicted.
Re: Strange getData setData behaviour
read it in via getData()
make some changes
push it back to the editor via setData()
then .submit() my form.
The odd thing is that my form submits nothing, not even the unaltered text.
Is there a better way?
Re: Strange getData setData behaviour
the only thing I got to work was using a callback function in setData that does the submit action. On the other you might manipulate it with sth like jQuery (but thats simply an ugly workaround).
Cheers,
flo
Re: Strange getData setData behaviour
Hi guys, take it easy, actually the secondary param of setData ( callback function ) was introduced since 3.0, you can find document here:
http://docs.cksource.com/ckeditor_api/s ... ml#setData
Re: Strange getData setData behaviour
I currently have a framework that validates fields and start by trimming them and doing various optimisations on them. By doing so, it calls setData.
Then the framework iterates over the fields to get the data and build a string to post with AJAX. It then calls getData. And on FF, it invariably returns an empty string. And my CKEditor fields are sent with no value...
Quite impossible to debug as well, as stepping or doing alert(xxx) gives the time to CKEditor to return something on getData, so whenever trying to debug, it actually works !
I have artificially disabled preprocessing for CKEditor values, but this hardly seems like a long term workaround.