onChange missing last character

1 Answer 779 Views
Editor
Shane
Top achievements
Rank 2
Iron
Iron
Iron
Shane asked on 28 Apr 2022, 07:34 PM

i am logging and saving the text with onChange and it seems to be missing the last character.

 

any idea what I'm doing wrong?

1 Answer, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 28 Apr 2022, 08:34 PM

Hello Shane,

Thank you for reaching out to us.

I have tested the following simple example with the Editor and the returned html within the onChange event contains the last entered change correctly:

Could you please modify the example so it matches your scenario and replicates the issue. Thus we will be able to test and debug it locally.

Looking forward to your reply.

 

Regards,
Konstantin Dikov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Shane
Top achievements
Rank 2
Iron
Iron
Iron
commented on 28 Apr 2022, 08:49 PM

that worked. I was using this instead of event.html. That is much easier.

const doc = event.target.state.view.state.doc;
const selection = event.target.state.view.state.selection;
const value = EditorUtils.getHtml(
ProseMirror.EditorState.create({
doc: doc,
selection: selection
})
);

Hyunrip
Top achievements
Rank 1
commented on 23 May 2022, 08:11 AM | edited

I have a same issue. last character is still missing when onChange is called.

ProseMirror that Shane said is not working for me.

 

Source code is simple

<Editor tools={[~~~]} contentStyle={{height:320}} onChange={changeEventHandler}/>

 const changeEventHandler = (e) => {
    if (e.target.view) {
      const view = e.target.view;
      if (view) {
        let htmlTxt = EditorUtils.getHtml(view.state);
        console.log(htmlTxt)
        // props.setContent(htmlTxt);
      }
    }
  }

 

 

 

"5" is missing!

How can I solve this?

 

Konstantin Dikov
Telerik team
commented on 24 May 2022, 08:30 PM

Hi Hyunprip,

The issue that you are facing is the same as the one in the original post, where the value is extracted from the state, which will not be updated at this stage (within the onChange event). Please use the approach demonstrated in the following example instead:

  const onChange = (ev) => {
    console.log(ev.html);
  };

Tags
Editor
Asked by
Shane
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Konstantin Dikov
Telerik team
Share this question
or