yup#DateSchema TypeScript Examples
The following examples show how to use
yup#DateSchema.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: validation.ts From firecms with MIT License | 6 votes |
function getYupDateSchema({
property,
parentProperty,
customFieldValidator,
name
}: PropertyContext<TimestampProperty>): AnySchema | DateSchema {
if (property.autoValue) {
return yup.object().nullable(true);
}
let schema: DateSchema<any> = yup.date();
const validation = property.validation;
if (validation) {
schema = validation.required
? schema.required(validation?.requiredMessage ? validation.requiredMessage : "Required").nullable(true)
: schema.notRequired().nullable(true);
if (validation.unique && customFieldValidator && name)
schema = schema.test("unique",
"This value already exists and should be unique",
(value) => customFieldValidator({
name,
property,
parentProperty,
value
}));
if (validation.min) schema = schema.min(validation.min, `${property.title} must be after ${validation.min}`);
if (validation.max) schema = schema.max(validation.max, `${property.title} must be before ${validation.min}`);
} else {
schema = schema.notRequired().nullable(true);
}
return schema;
}