Search code examples
jqueryajaxformsckeditor

How to clear ckeditor form after submitting with ajax?


I am using CKeditor, Jquery and plugin jquery form.

CKEDITOR.replace( 'comment-textarea' );
function CKupdate(){
    for ( instance in CKEDITOR.instances )
        CKEDITOR.instances[instance].updateElement();
}

$(document).ready(function(){   
    var options = {
        success: function (html) {
            $('#comments').append(html);
        },
        clearForm: true 
    };

    $('#formcomments').submit(function() {
        CKupdate();
    });
    $('#formcomments').ajaxForm(options);
});   

I am using clearForm: true, But after submiting a form, value of the textarea Ckeditor is not cleared. How to clear the textarea ckeditor?


Solution

  • I use function setData and all works fine:

    function CKupdate(){
        for ( instance in CKEDITOR.instances ){
            CKEDITOR.instances[instance].updateElement();
            CKEDITOR.instances[instance].setData('');
        }
    }
    
    $(document).ready(function(){   
        CKEDITOR.replace( 'comment-textarea' );
    
        var options = {
            success: function (html) {
                $('#comments').append(html);
            },
            clearForm: true 
        };
    
        $('#formcomments').submit(function() {
            CKupdate();
        });
        $('#formcomments').ajaxForm(options);
    });