I am using CKEditor 4 on a textarea filed in a page, when I open data i nedit form a grid in my page, I put the setData() function to set the content inside the textarea inside a on instanceReady event, but sometimes it doesn’t enter inside the instanceReady event function. This is my js code:
function prepCkEditor() {
var oFCKeditor = CKEDITOR.instances.EMAIL_DESC_TEMPLATETextBox;
if (!oFCKeditor) {
CKEDITOR.replace('EMAIL_DESC_TEMPLATETextBox', {
language: editorlang,
toolbar: 'helpsi',
skin: 'moono',
scayt_autoStartup: CONFIGURAZIONE.enableSpellCheck,
scayt_sLang: $('#hfUSER_LANGEXTENDED').val().replace('-', '_'),
scayt_disableOptionsStorage: 'lang'
});
}
}
prepCkEditor();
var oFCKeditor = CKEDITOR.instances.EMAIL_DESC_TEMPLATETextBox;
if (oFCKeditor) {
console.log(oFCKeditor.status);
oFCKeditor.on('instanceReady', function () {
oFCKeditor.setData(template.TemplateBody);
});
}
The console.log statement put before the on instanceReady line prints ‘ready’ so it seems that the editor is fully loaded, but it doesn’t enter inside the function to set the data. What could it be the problem?
If I check in debug in the browser development tools, it wiorks but the status that prints is unloaded
2
Answers
Thanks, I think this can be the solution, how can I pass the data inside the editor? I tried in this way
But when I'm debugging, inside the on instanceReady event, the data variable is empty, even if I'm passing text inside the data parameter to the function
EDIT: The problem of the text not inserted i nthe editor was due to another call that overlapped to this to reset the editor, I removed the first call, thanks
This is because sometimes it is ready and sometimes it is not by the time you reach this line of code.
You should attach the event when you create the instance using the
on
property.