Vimalan Jaya Ganesh Vimalan Jaya Ganesh - 17 days ago 5
jQuery Question

CKEditor and JQuery Validation: error message not disappearing after entering text

The JQuery validation error message is not disappearing even after entering text in CKEditor.

Fiddler: http://jsfiddle.net/BmZ93/458/

Code:

$(document).ready(function() {
$('#add-job').validate({
ignore: [],
rules: {
editor1: {
required: function()
{
CKEDITOR.instances.editor1.updateElement();
}
}
},
messages: {
Job_Title: "Required",
Job_Location: "Required",
jobid: "Required",
Job_Cat: "Required",
editor1: "Required"
},
/* use below section if required to place the error*/
errorPlacement: function(error, element)
{
if (element.attr("name") == "editor1")
{
error.insertBefore("textarea#editor1");
} else {
error.insertBefore(element);
}
}
});
});


enter image description here

Expectation:
Once the user enters some text in ckeditor, the validation error message should disappear.

Any suggestion / direction will be greatly appreciated.

Answer

You can add this on your JS, it will hide the error when the CKEditor have content:

CKEDITOR.instances.editor1.on('change', function() {    
    if(CKEDITOR.instances.editor1.getData().length >  0) {
      $('label[for="editor1"]').hide();
    }
});

Demo: http://jsfiddle.net/BmZ93/460/