Function getValidationSchemaFromYams

  • If you use useCubicWebForm, then there is no need to manually use this function.

    But if you want to write your own hooks, you might still need the yup validation. In that case, you can use this function to generate a Yup object, which you can then use in the the rest of your app.

    Parameters

    • yams: EntitySchema<EntityRawSchemaArray, RelationDefinitionRawSchemaArray<EntityRawSchemaArray>, EntityRawSchema>

      The entity schema containing all the attributes of the entity.

    • customErrorsTranslations: CustomYupErrorsTranslations

      An object for custom translations

    • Optional omittedFields: string[]

      The list of attributes/relations to ignore.

    Returns OptionalObjectSchema<{}, AnyObject, TypeOfShape<{}>>

    The yup object schema containing various primitive types to validate.

    Example

    Here is an example usage with react-hook-form:

    import {useForm} from "react-hook-form";
    import {yupResolver} from "@hookform/resolvers/yup";
    import {getValidationSchemaFromYams} from "@cubicweb/yup";

    const entityTypeParser = getValidationSchemaFromYams(
    entityTypeSchema,
    errorsTranslations,
    omittedFields
    );

    const {...} = useForm({
    resolver: yupResolver(entityTypeParser),
    });

Generated using TypeDoc