React Draft Wysiwyg: Empty validator check

Viewed 922

I am trying to write a validator that will check to see if the value is "<p></p>↵"... and if it is, display the required message. However, I can't seem to target the ↵ no matter what I try. I've tried to use trim() as well, but haven't had any luck.

export const isRichTextImageEditorRequired = (value) => value &&
    (!/(\r\n|\n|\r)/.test(value) || isEmpty(value)) ?
    'This field is required' : undefined;
2 Answers

try

if (convertToRaw(editorState.getCurrentContent()).blocks.length === 1 & convertToRaw(editorState.getCurrentContent()).blocks[0].text === '') {

console.log("field required"); }

this is case empty <p></p>

trim() works for me, refer the code below . Kindly console you "value" and check if it has any property. In my case it is 'editorText'

code : values.editorText.trim() === "<p></p>"

Related