yup#BooleanSchema TypeScript Examples

The following examples show how to use yup#BooleanSchema. 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 vote down vote up
function getYupBooleanSchema({
                                 property,
                                 parentProperty,
                                 customFieldValidator,
                                 name
                             }: PropertyContext<BooleanProperty>): BooleanSchema {
    let schema: BooleanSchema<any> = yup.boolean();
    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
                }));
    } else {
        schema = schema.notRequired().nullable(true);
    }
    return schema;
}