yup

yup.js Validate number field is larger than sibling, or nullable

梦想与她 提交于 2021-02-19 05:21:50
问题 I'm using Yup.js to validate some form fields. I have two integer fields, Year Built & Year Renovated . Year Built is a required field, Year Renovated is not. Year renovated can be left blank, however if there is a value it should be larger than year built (for a renovation certainly must occur after the date it was built). I believe I need to use yup's ref() as well as yup's when() function. I've tried the following: let currentYear = new Date().getFullYear(); yup.object().shape({ yearBuilt

Dynamic Validation Messages Using Yup and Typescript

别来无恙 提交于 2020-12-06 07:03:29
问题 I am trying to create some custom error messages with Yup to determine if the user's email address is in use. I have created the following promise to try and catch a server communication error: .test( { name: 'Email Check', test: value => { if (value.includes("@")) { return new Promise<yup.ValidationError>((resolve, reject) => { let client = new RegistrationApi(); client.emailCheck(value, x => x ? resolve(undefined) : resolve(new yup.ValidationError("E-mail address already used", value, "")),

Dynamic Validation Messages Using Yup and Typescript

偶尔善良 提交于 2020-12-06 07:02:30
问题 I am trying to create some custom error messages with Yup to determine if the user's email address is in use. I have created the following promise to try and catch a server communication error: .test( { name: 'Email Check', test: value => { if (value.includes("@")) { return new Promise<yup.ValidationError>((resolve, reject) => { let client = new RegistrationApi(); client.emailCheck(value, x => x ? resolve(undefined) : resolve(new yup.ValidationError("E-mail address already used", value, "")),

Create dynamic Yup validation schema from JSON

ぐ巨炮叔叔 提交于 2020-12-01 09:47:36
问题 I'm trying to use Yup along with Formik in my react form. The form fields are going to be dynamic so as their validations. export const formData = [ { id: "name", label: "Full name", placeholder: "Enter full name", type: "text", required: true, value: "User name", values: [], validations: [ { type: "minLength", value: "5", error_message: "name should be atleast 5 char long" }, { type: "maxLength", value: "10", error_message: "name should be atleast 5 char long" } ] }, { id: "email", label: