Question

I am working in an ASP.NET MVC application. The application has a form that is brought in via @Ajax.ActionLink and this form has a textarea that I am binding CkEditor to.

I have specific requirements that involve grabbing whatever the user has typed in CKEditor and passing onto somewhere on the press of a button.

So what I am currently doing is binding an onChange event to CKEditor, which works fine assuming I do change something inside the CKEditor textarea.

However, what if the user gets the form, doesn't change anything, and then presses the button to grab the content. It won't work because my code will only grab after something has changed. So my question, how can I run the following:

/*
* As the user types the email body insert, this function updates the
* value on the hidden input field on [ form#EmailPreviewForm ] above.
*/
var data = CKEDITOR.instances.emailBody.getData();
$('#emailBodyInsert').val(data);

Only after the CKEditor has finished initializing, because otherwise I get an error saying undefined on emailBody; this makes sense, since at that point CKEditor has not been initialized.

Was it helpful?

Solution

Use the CKEditor instanceready event:

CKEDITOR.replace('editor1', {
    on :
    {
        instanceReady : function( ev ) {
            // your code here
        }
    }
} );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top