Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.createError();
return true;
};
mixed.test('with-context', 'it uses function context', testContext);
mixed.test({
test: testContext,
});
mixed.test({
message: ({ passed }) => (passed ? 'You passed' : 'You failed'),
name: 'checkParams',
params: { passed: true },
test: value => !!value,
});
// mixed with concat
yup.object({ name: yup.string() }).concat(yup.object({ when: yup.date() })); // $ExpectType ObjectSchema<{ name: string; } & { when: Date; }>
yup.mixed().concat(yup.date()); // $ExpectType MixedSchema
// Async ValidationError
const asyncValidationErrorTest = (includeParams: boolean) =>
function(this: TestContext): Promise {
return new Promise(resolve =>
resolve(
includeParams
? this.createError({ path: 'testPath', message: 'testMessage', params: { foo: 'bar' } })
: this.createError(),
),
);
};
mixed.test('async-validation-error', 'Returns async ValidationError', asyncValidationErrorTest(true));
mixed.test('async-validation-error', 'Returns async ValidationError', asyncValidationErrorTest(false));
label: 'Surveys and Polls',
},
{ value: InKindDescriptionTypeEnum.TRAVEL, label: 'Travel Expenses' },
{ value: InKindDescriptionTypeEnum.UTILITIES, label: 'Utilities' },
{
value: InKindDescriptionTypeEnum.WAGES,
label: 'Wages/Salaries/Benefits',
},
],
},
},
// Not required if occupation & employer name/address filled in
occupationLetterDate: {
label: 'Occupation Letter Date',
component: DateField,
validation: Yup.date(),
},
// Required UNLESS the payment method is Credit Card (Online).
// or if there is a donor portal where donors can attest digitally, that may affect this
linkToDocumentation: {
label: 'Link to Documentation?',
component: TextField,
validation: Yup.string(),
},
notes: {
label: 'Notes?',
component: TextField,
validation: Yup.string(),
},
};
// Uses Formik validate, with an additional object _visibleIf
const stixRelationValidation = (t) => Yup.object().shape({
weight: Yup.number()
.typeError(t('The value must be a number'))
.integer(t('The value must be a number'))
.required(t('This field is required')),
first_seen: Yup.date()
.typeError(t('The value must be a date (YYYY-MM-DD)'))
.required(t('This field is required')),
last_seen: Yup.date()
.typeError(t('The value must be a date (YYYY-MM-DD)'))
.required(t('This field is required')),
description: Yup.string(),
role_played: Yup.string(),
});
const validationSchema = () => Yup.object().shape({
name: Yup.string()
.required('This field is required'),
location: Yup.string()
.required('This field is required'),
description: Yup.string()
.required('This field is required'),
startDate: Yup.date()
.required('This field is required'),
endDate: Yup.date()
.required('This field is required'),
});
Editor.defaultProps.theme ='one-light'
localizers(require('globalize'))
Form.addInputTypes(types)
var nameSchema = yup.string()
.default('')
.required('You must provide a name');
var modelSchema = yup.object({
name: yup.object({
first: nameSchema,
last: nameSchema
}),
dateOfBirth: yup.date()
.required('Please enter a date of birth')
.max(new Date(), "You can't be born in the future!"),
colorId: yup.number(),
age: yup.number()
.nullable()
.required('Please enter an age')
.positive('Ages must be a positive number')
})
let MyDateInput = props =>
var reqMap = { 'react-formal': 'Form', 'react': 'React', 'react-formal-inputs': 'types' }
, scope = {
Form, React, ReactDOM, yup, modelSchema, MyDateInput, types,
}
})
.nullable();
}
if (type === 'email') {
schema = schema.email(errorsTrads.email);
}
if (['number', 'integer', 'biginteger', 'float', 'decimal'].includes(type)) {
schema = yup
.number()
.transform(cv => (isNaN(cv) ? undefined : cv))
.typeError();
}
if (['date', 'datetime'].includes(type)) {
schema = yup.date();
}
Object.keys(validations).forEach(validation => {
const validationValue = validations[validation];
if (
!!validationValue ||
((!isBoolean(validationValue) &&
Number.isInteger(Math.floor(validationValue))) ||
validationValue === 0)
) {
switch (validation) {
case 'required':
schema = schema.required(errorsTrads.required);
break;
case 'max':
schema = schema.max(validationValue, errorsTrads.max);
const reportValidation = (t) => Yup.object().shape({
name: Yup.string().required(t('This field is required')),
published: Yup.date()
.typeError(t('The value must be a date (YYYY-MM-DD)'))
.required(t('This field is required')),
report_class: Yup.string().required(t('This field is required')),
description: Yup.string(),
});
import { useForm } from 'react-hook-form';
import * as yup from 'yup';
let renderCounter = 0;
const validationSchema = yup.object().shape(
{
firstName: yup.string().required(),
lastName: yup
.string()
.max(5)
.required(),
min: yup.number().min(10),
max: yup.number().max(20),
minDate: yup.date().min('2019-08-01'),
maxDate: yup.date().max('2019-08-01'),
minLength: yup.string().min(2),
minRequiredLength: yup
.string()
.min(2)
.required(),
selectNumber: yup.string().required(),
pattern: yup.string().matches(/\d+/),
radio: yup.string().required(),
checkbox: yup.string().required(),
exclusivelyRequiredOne: yup.string().when('exclusivelyRequiredTwo', {
is: '',
then: yup.string().required(),
otherwise: yup.string().length(0),
}),
exclusivelyRequiredTwo: yup.string().when('exclusivelyRequiredOne', {
is: '',