This is a migrated thread and some comments may be shown as answers.

How to get change in onExecute event for Kendo React Editor

1 Answer 509 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
yilmaz
Top achievements
Rank 1
yilmaz asked on 13 Sep 2019, 12:26 PM
When Kendo React editor changes its content by user typing in it, how to get the latest state of html from editor? When I use the get html method from EditorTools, it gives me the state without the change.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 16 Sep 2019, 07:22 AM

Hello,

The current state can be retrieved during the event from the transaction event parameter on the onExecute event:
const nextState = ProseMirror.EditorState.create({
  doc: transaction.doc,
  selection: transaction.selection
}); // this will create the next state

 
const editorValue = EditorUtils.getHtml(nextState);


Also, please have in mind that the onExecute will be fired when the selection is changed as well, that is why it is a good idea to add some logic to check for that to not make unnecessary updates:
if (state.doc.eq(transaction.doc)) {
  return;
}

This is an  example

https://stackblitz.com/edit/react-n1jgym?file=app/main.jsx

Also, I have two side notes:

1) As when the document becomes bigger serializing it with "getHtml" could become slower, we can suggest during onExecute to only save the document in the state and serialize it during another event as save button.

2) We have an example with a HOC that adds an Editor with an onChange event that handles this internally. Please take a look at it as it can prove helpful:

https://stackblitz.com/edit/react-urtld6-rzwtsv?file=app/controlled-editor.jsx

Regards,
Stefan
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
yilmaz
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or