If there any flag or API to turn off the rich text saving of this component. We have an editor that we need to allow the user to view the source/html tags as well as the WYSIWYG output.
Thanks!
Does the plaintext example help here? Not totally sure I understand the request, sorry.
I look at https://github.com/facebook/draft-js/blob/master/examples/plaintext/plaintext.html, i could not see how to convert a rich text to a plain text. We want to have a button say Source which once click, it will convert the rich text to plain text so that we can save the plain text into the database. Not the rich content. Make sense?
Thanks!
If you just want the plaintext contents, without any of the style information, you can use http://facebook.github.io/draft-js/docs/api-reference-content-state.html#getplaintext.
const myText = this.state.editorState.getCurrentContent().getPlainText();
Alternatively, you can use convertToRaw to get a vanilla JS version of the ContentState, then do whatever you need with it.
Does that help?
Going to go ahead and close this -- I think the utilities above should provide what you need.
It should but we can't test it out as the sample codes are all in ES6 and ours are not, yet.
Most helpful comment
If you just want the plaintext contents, without any of the style information, you can use http://facebook.github.io/draft-js/docs/api-reference-content-state.html#getplaintext.
Alternatively, you can use
convertToRawto get a vanilla JS version of theContentState, then do whatever you need with it.Does that help?