I'm using Draft-js with Formik with yup for validation of the Draft EditorState component.
I assumed I would be able to check that EditorState is not blank by using the following yup test:
//Each note has a string title and a body, which is a Draft EditorState
const validationSchema = yup.object().shape({
title: yup.string(),
body: yup.object()
.test("has text", "Cannot save an empty note", (value) => {
return value.getCurrentContent().hasText(); //boolean
}),
})
However, I get the error:
Uncaught (in promise) TypeError: Cannot read property 'length' of undefined at yupToFormErrors (formik.esm.js:491) at formik.esm.js:174
Is this a bug with formik, or am I using yup incorrectly?
Other information:
Inside validationSchema, I get the following:
console.log(value.getCurrentContent().hasText()) //returns undefined
console.log(value.getCurrentContent()) //returns undefined
But inside an onChange handler for EditorState ('body' field) it works properly:
console.log(value.getCurrentContent().hasText()) //returns true or false