0

This answer is only working if the editor has only text inside. max-length check is not working if markup is applied to the text like bold or italics. Can anyone please help me in this case.

handleBeforeInput={val => {
    const textLength = editor.getCurrentContent().getPlainText().length;
     if (val && textLength >= this.state.maxLength) {
        return 'handled';
     }
}}
handlePastedText={val => {
  const textLength = editor.getCurrentContent().getPlainText().length;
  return ((val.length + textLength) >= this.state.maxLength);
}}
    onEditorStateChange = editor => {
        let bodyLength = editor.getCurrentContent().getPlainText('').length;
        if (bodyLength <= this.state.maxLength) {
            const editorHTML = draftToHtml(convertToRaw(editor.getCurrentContent()));
            let hasText = editor.getCurrentContent().hasText();
            this.props.changeTemplateBody(editorHTML, hasText);
            this.setState({ editor, editorHTML, hasText, bodyLength });            
        } else {
            return "handled;
        }
    }

0 Answers0