yup-phone icon indicating copy to clipboard operation
yup-phone copied to clipboard

Overrides yup's required() error message when no value is present.

Open mantism opened this issue 2 years ago • 2 comments

Here is a snippet from my yup validation schema. I would like to pass a message into the required function to display something user-friendly if they don't enter any text.

emergencyPhoneNumber: Yup.string()
  .phone()
  .required('Emergency contact phone number is required.'),

I know I can provide a custom error message through phone() however, as this is an add-on to yup, it should support yup's expected behavior. If possible, I would like to be able to provide an error message for when a user input's an invalid phone number and a required message if they don't input anything.

mantism avatar Jul 16 '22 15:07 mantism

Having this same issue.

aaronbdixon avatar Aug 03 '22 14:08 aaronbdixon

If you put chain it like Yup.string().required("Message").phone() you should get the required message.

aaronbdixon avatar Aug 03 '22 14:08 aaronbdixon