Reputation: 1959
I'm new to using CKEditor, and the API is a little confusing...
What I want to do is to clear the contents of the CKEditor on the first focus by the user, and only if the form hasn't been reloaded.
Why? I'm putting some instructions in the CKEditor field itself and would like for it to get cleared the first time they focus the editor. I don't want the contents to get cleared on subsequent focuses.
Thanks for any help!
The JS framework I'm using is jQuery.
Upvotes: 1
Views: 6289
Reputation: 1959
I solved this problem by storing the contents in the session. If the form round-trips to the server and fails validation, I just load the contents from the session. I store it to the session via Ajax on blur
event. Once the form validates and posts to the db I destroy the session.
Upvotes: 0
Reputation: 3211
declare a global variable in javascript,
<script type="text/javascript">
var isFirst = 1;
</script>
and then try adding onfocus event , like this:
CKEDITOR.instances.editor1.on( 'onfocus', function( evt ) {
if(isFirst)
{
isFirst = 0;
CKEDITOR.instances.editor1.setData( '' );
}
});
Upvotes: 2