Draft-js: How to get editor innerText and manipulate?

Created on 19 Feb 2018  路  6Comments  路  Source: facebook/draft-js

I need those code to get innerText and manipulate them for make it better.. if anyone know about this please help me.....

needs more info support

Most helpful comment

Some helpful methods:
ContentState.getPlainText() -> https://draftjs.org/docs/api-reference-content-state.html#getplaintext

ContentState.createFromText() -> https://draftjs.org/docs/api-reference-content-state.html#createfromtext

You could read the "innerText" of the editor using getPlainText, change the text, and then create a new updated contentState using createFromText and then pass the updated contentState to your Draft.js editor.

All 6 comments

Hi @Maijied - can you give an example of what you want to do? I need more info to help you.

Some helpful methods:
ContentState.getPlainText() -> https://draftjs.org/docs/api-reference-content-state.html#getplaintext

ContentState.createFromText() -> https://draftjs.org/docs/api-reference-content-state.html#createfromtext

You could read the "innerText" of the editor using getPlainText, change the text, and then create a new updated contentState using createFromText and then pass the updated contentState to your Draft.js editor.

@flarnie how i'll copy editor innerText by a button. Like Copy To Clipboard method. Thanks in advance.

And basically i work in draft.js for making a editor where editor automatically check #Bangla spell by calling API and suggest 2 gram data(Text).

I think this should demonstrate how you can do it:

https://jsfiddle.net/m6z0xn4r/452/

This demonstrates -

  • how to copy the current selection to the clipboard
  • how to set the selection in the Draft editor
  • how to get the text of the editor

I hope you can use the example to do what you need, let me know if there is more to your question.

After press the enter button ,text line get a new div .That's why i cant implement my spell checker api for underline the false words . How i get all text or by which div?
and push those words back to the same div?
@flarnie

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ufo22940268 picture ufo22940268  路  3Comments

mvnnn picture mvnnn  路  3Comments

igorpreston picture igorpreston  路  3Comments

pklavins picture pklavins  路  3Comments

abeq picture abeq  路  3Comments