Thursday 23 May 2019

How to validate checkboxes with a custom message (Using Yup)?

So, I have a checkbox that needs to be checked before the Form gets sent and I wanna display a message in case the user hasn't checked it.So far I have:infoTrue: Yup.boolean() .oneOf([true]) .required('Do you certify that the information you entered is correct?'),I am not sure what I am doing is correct. If I keep the required, it displays a msg from Yup on how it didn't equal true referring to the test of oneOf([true]). If I remove it, Yup just ignores it. If I remove theoneOf([true]) and keep the required, Yup also ignores it.I wanna know how to include a custom message for other failed test cases. For example, I have a datepicker and I told Yup I want it to be between 2 values only. It displays a message but it's Yup's message and I wanna include my own. Here's what I have so far:selectedDate: Yup.date() .min('January 1960') .max('December 1990') .required('Please choose a date between Jan 1960 and Dec 1990'),Thanks in advance.

Submitted May 23, 2019 at 03:07PM by Lojain19

No comments:

Post a Comment