Reputation: 11
How to check the textarea data is blank in CKEDITOR 5.
<button type="button" class="btn" onclick="mlksv();">example</button>
<textarea name="mlkzlk" id="editor" placeholder="my abilities"></textarea>
Script Code:
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then( editor => {
console.log( editor );
} )
.catch( error => {
console.error( error );
} );
function mlksv() {
var editorgmgm = $('#editor').attr('id');
var _contents = CKEDITOR.instances.editorgmgm.document.getBody().getText();
if (_contents == '') {
alert('null') ;
}else{
alert("not null");
}
}
Upvotes: 1
Views: 1054
Reputation: 1333
In CKEditor 5, you now have to keep a reference to the instantiated editor.
let theEditor; // reference to ckeditor obj
ClassicEditor
.create( document.querySelector( '#editor' ) )
.then( editor => {
theEditor = editor;
console.log( editor );
...
Then, use the getData()
method to retrieve the content.
var _contents = theEditor.getData();
if (_contents == '') {
...
Upvotes: 1