Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Draft Wysiwyg: Empty validator check

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;
like image 769
user9848916 Avatar asked Mar 15 '26 10:03

user9848916


1 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>

like image 119
lohnsonok Avatar answered Mar 16 '26 22:03

lohnsonok