I am using CKEDITOR 5 to replace some textarea that will be used to publish informative content on a website. The problem I have when validating that the CKEDITOR is not empty, I have tried several things but nothing that I can give with the solution. What I have done is the following:
document.querySelector( '#btn_noticia' ).addEventListener( 'click', () => {
var DataNoticia = editor_noticia.getData();
if(DataNoticia==""){
alert("Debes escribir algo en el editor para publicar");
}else{
$("#btn_noticia").attr("disabled",true).text("Publicando...");
$.post('ajax.php?mode=nueva_noticia',{contenido_noti:DataNoticia},function(r){
if (r==1) {
$.notify({
icon: 'font-icon font-icon-check-circle',
title: '<strong>Noticia publicada</strong>',
message: ''
},{
type: 'success'
});
setTimeout(function(){
location.reload();
},2000);
}else{
alert(r);
$("#btn_noticia").attr("disabled",false).text("Publicar");
}
})
}
});
With this way the CKEDITOR this empty publishes me the content, the closest I was was placing this in the conditional
if($("#contenido_noti iframe").contents().find("body").text()=="")
With this if you validate me when it is empty, but still the CKEDITOR has text keeps telling me that it is empty. I keep trying and nothing that I give with the solution.