Mathieu Bertin
Mathieu Bertin

Reputation: 465

CKEDITOR's insertHtml not working except in setTimeout

I have a function called fillFields and calling CKEDITOR.instances.myinstance.insertHtml('<p>My stuff</p>'); within that will not work but the following will:

setTimeout(function(){
        CKEDITOR.instances.myinstance.insertHtml('<p>My stuff</p>');
    }, 1);

Any clues as to why this is?

Upvotes: 0

Views: 425

Answers (2)

Mathieu Bertin
Mathieu Bertin

Reputation: 465

The problem stemmed from resetting the editor before inserting html by calling setData and not using the callback to then call insertHtml which led to setData resetting my editor after having inserted the html.

Upvotes: 0

Wizard
Wizard

Reputation: 3151

If you are trying to enter data in CKEditor after you initialize it, you have to wait until CKEditor instance is loaded and ready for interaction. Use the instanceReady event:

CKEDITOR.instances.myinstance.on('instanceReady', function(evt) {
    evt.editor.insertHtml('<p>My stuff</p>');
});

Upvotes: 1

Related Questions