UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

21 lines (20 loc) 766 B
import { z } from 'zod'; import { buildCommonSchema } from '../../registry/validation'; // undefined (optional) for unspecified, otherwise a finite numeric value. Note that // null would be nicer, but formio's schema does not support null for validate.min, // validate.max or defaultValue const numberSchema = z.number().finite().optional(); const defaultValueSchema = z.object({ defaultValue: numberSchema.or(z.null()), }); const numberSpecific = z.object({ decimalLimit: z.number().int().min(0).max(10).optional(), validate: z .object({ min: numberSchema, max: numberSchema, }) .optional(), }); const schema = ({ intl }) => buildCommonSchema(intl).and(defaultValueSchema).and(numberSpecific); export default schema;