BlackBelt2025
BlackBelt2025

Reputation: 503

CKEDITOR 5 set body `id`

Is there a way to set the id attribute of the body of a CKEDITOR 5 ClassicEditor?

In cke4, there was a config option BodyID you could set when creating the editor instance, but I was unable to find something similar for cke5 in the docs or on SO.

I need to attach Countable.js to the editor to perform wordcount and feed that info to other parts of the code (over which I have no control)

I may have multiple editors active on the page at once.

Upvotes: 0

Views: 1517

Answers (2)

BlackBelt2025
BlackBelt2025

Reputation: 503

Apparently, CKE5 does not play well with CountableJS when deleting text using the backspace key. The live wordcount does not get updated as it would in a normal textarea.

I used a different solution:

editor.document.on('changesDone`, (evt,data) => {
  Countable.once(editorelement,callback())
});

This seems to work for backspace/delete as well as text input and setData().

Upvotes: 0

Reinmar
Reinmar

Reputation: 22013

In CKEditor 5 the root editable element can be easily retrieved using the API:

editor.ui.view.editable.element

See:

enter image description here

You don't need to set any ids – just get the element and pass it to Countable.js:

const callback = counter => console.log(counter);
const area = editor.ui.view.editable.element;

Countable.live(area, callback);

Upvotes: 1

Related Questions