Validate that CKEDITOR is not empty

0

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.

    
asked by Alejo Mendoza 07.09.2018 в 23:49
source

1 answer

0

The solution I found it in the following way:

I have made a console.log(DataNoticia) and the CKEDITOR when it is empty shows the following <p>&nbsp;</p> .

And the conditional has stayed like this:

var DataNoticia = editor_noticia.getData();
if(DataNoticia=="<p>&nbsp;</p>"){
    alert("Debes llenar ambos campos");
    return false;
}else{
 ///
}
    
answered by 10.09.2018 в 21:21