draftjs

How to limit Max Length of Draft js

五迷三道 提交于 2019-11-30 15:03:41
问题 How to limit max characters in draft js? I can get length of the state like that, but how to stop updating component? var length = editorState.getCurrentContent().getPlainText('').length; 回答1: You should define handleBeforeInput and handlePastedText props. In handler-functions, you check the length of current content + length of pasted text and if it reaches the maximum you should return 'handled' string. UPD 21.03.2018: Upgraded to the last versions of react/react-dom (16.2.0) and Draft.js

How to limit Max Length of Draft js

孤街浪徒 提交于 2019-11-30 13:09:41
How to limit max characters in draft js? I can get length of the state like that, but how to stop updating component? var length = editorState.getCurrentContent().getPlainText('').length; You should define handleBeforeInput and handlePastedText props. In handler-functions, you check the length of current content + length of pasted text and if it reaches the maximum you should return 'handled' string. UPD 21.03.2018: Upgraded to the last versions of react/react-dom (16.2.0) and Draft.js (0.10.5). Working example - https://jsfiddle.net/Ln1hads9/11/ const {Editor, EditorState} = Draft; const MAX