Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 441
serg66 Avatar asked Mar 26 '11 13:03

serg66


3 Answers

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);
}); 
like image 114
serg66 Avatar answered Nov 09 '22 10:11

serg66


Try something like $("#comment-textarea").val(""); ... it should go here.

$('#formcomments').submit(function() {
        CKupdate();
$("#comment-textarea").val("");
    });

#comment-textarea is the id of the textarea you want to clear and .val(' ') sets it's value to ' ' - notice the space between the ';

like image 25
George I Avatar answered Nov 09 '22 10:11

George I


Simply create instance and use setHtml

use this inside submit

var Editor1 = FCKeditorAPI.GetInstance('comment-textarea'');
Editor1.SetHTML();

for ckeditor

setData

http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData

like image 25
Gowri Avatar answered Nov 09 '22 08:11

Gowri