UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

23 lines (22 loc) 1.03 kB
import { defineMessages } from 'react-intl'; import { z } from 'zod'; import { LABELS } from '../../components/builder/messages'; import { buildCommonSchema, getErrorMap, isInvalidStringIssue } from '../../registry/validation'; const VALIDATION_MESSAGES = defineMessages({ email: { id: "Q0SS8P", defaultMessage: [{ type: 1, value: "field" }, { type: 0, value: " must be a valid email." }] } }); const buildDefaultValueSchema = (intl) => { const emailSchema = z .string({ errorMap: getErrorMap(issue => { if (isInvalidStringIssue(issue) && issue.validation === 'email') { const fieldLabel = intl.formatMessage(LABELS.defaultValue); return intl.formatMessage(VALIDATION_MESSAGES.email, { field: fieldLabel }); } return; }), }) .email() .optional(); return z.object({ defaultValue: emailSchema }); }; const schema = ({ intl }) => buildCommonSchema(intl).and(buildDefaultValueSchema(intl)); export default schema;