@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
24 lines (23 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
const validation_1 = require("../../registry/validation");
const textareaSchema = zod_1.z.string().optional();
// case for when component.multiple=false
const singleValueSchema = zod_1.z
.object({ multiple: zod_1.z.literal(false) })
.and(zod_1.z.object({ defaultValue: textareaSchema }));
// case for when component.multiple=true
const multipleValueSchema = zod_1.z
.object({ multiple: zod_1.z.literal(true) })
.and(zod_1.z.object({ defaultValue: textareaSchema.array() }));
// Omit `autoExpand` as it will be set in the UI via a checkbox
const textareaSpecific = zod_1.z.object({
validate: zod_1.z.object({
maxLength: zod_1.z.number().int().gte(1).optional(),
}),
rows: zod_1.z.number().int().gte(1).optional(),
});
const defaultValueSchema = singleValueSchema.or(multipleValueSchema);
const schema = ({ intl }) => (0, validation_1.buildCommonSchema)(intl).and(textareaSpecific).and(defaultValueSchema);
exports.default = schema;