Skip to content

The Open Source DocuSign Alternative.

fix: prefill fields (#1689)

Catalin Pit65be37514f29
diff --git a/packages/lib/server-only/template/create-document-from-template.ts b/packages/lib/server-only/template/create-document-from-template.ts
index 860f8cb98..477ebba0b 100644
--- a/packages/lib/server-only/template/create-document-from-template.ts
+++ b/packages/lib/server-only/template/create-document-from-template.ts
@@ -118,6 +118,7 @@ const getUpdatedFieldMeta = (field: Field, prefillField?: TFieldMetaPrefillField
...existingMeta,
type: 'text',
label: field.label,
+ placeholder: field.placeholder,
text: field.value,
};
@@ -134,6 +135,7 @@ const getUpdatedFieldMeta = (field: Field, prefillField?: TFieldMetaPrefillField
...existingMeta,
type: 'number',
label: field.label,
+ placeholder: field.placeholder,
value: field.value,
};
@@ -190,8 +192,16 @@ const getUpdatedFieldMeta = (field: Field, prefillField?: TFieldMetaPrefillField
const checkboxMeta = result.data;
+ if (!field.value) {
+ throw new AppError(AppErrorCode.INVALID_BODY, {
+ message: `Value is required for CHECKBOX field ${field.id}`,
+ });
+ }
+
+ const fieldValue = field.value;
+
// Validate that all values exist in the options
- for (const value of field.value) {
+ for (const value of fieldValue) {
const valueExists = checkboxMeta.values?.some((option) => option.value === value);
if (!valueExists) {
@@ -203,7 +213,7 @@ const getUpdatedFieldMeta = (field: Field, prefillField?: TFieldMetaPrefillField
const newValues = checkboxMeta.values?.map((option) => ({
...option,
- checked: field.value.includes(option.value),
+ checked: fieldValue.includes(option.value),
}));
const meta: TCheckboxFieldMeta = {
diff --git a/packages/lib/types/field-meta.ts b/packages/lib/types/field-meta.ts
index 89b58aaed..ee2d9172f 100644
--- a/packages/lib/types/field-meta.ts
+++ b/packages/lib/types/field-meta.ts
@@ -130,28 +130,30 @@ export const ZFieldMetaPrefillFieldsSchema = z
z.discriminatedUnion('type', [
z.object({
type: z.literal('text'),
- label: z.string(),
- value: z.string(),
+ label: z.string().optional(),
+ placeholder: z.string().optional(),
+ value: z.string().optional(),
}),
z.object({
type: z.literal('number'),
- label: z.string(),
- value: z.string(),
+ label: z.string().optional(),
+ placeholder: z.string().optional(),
+ value: z.string().optional(),
}),
z.object({
type: z.literal('radio'),
- label: z.string(),
- value: z.string(),
+ label: z.string().optional(),
+ value: z.string().optional(),
}),
z.object({
type: z.literal('checkbox'),
- label: z.string(),
- value: z.array(z.string()),
+ label: z.string().optional(),
+ value: z.array(z.string()).optional(),
}),
z.object({
type: z.literal('dropdown'),
- label: z.string(),
- value: z.string(),
+ label: z.string().optional(),
+ value: z.string().optional(),
}),
]),
);