I am attempting to validate my schema using yup:
import * as yup from "yup";
let schema = yup.object().shape({
name: yup.string().min(5)
});
const x = { name: "" };
// Check validity
schema
.validate(x, { abortEarly: false })
.then((result) => {
console.log({ result });
})
.catch((err) => {
console.log({ err });
});
The field name
is empty in the object x
, yet yup throws an error for min
. Why is this happening? Is there a specific rule I can use to address this issue?
I want to apply the min
validation only if there are any characters present in the x
object. How can I achieve this using yup functions?