diff --git a/src/lib/forms-shared.ts b/src/lib/forms-shared.ts index 714e795..88bf9c1 100644 --- a/src/lib/forms-shared.ts +++ b/src/lib/forms-shared.ts @@ -102,6 +102,7 @@ export function applyVariables( homeowner?: HomeownerLite | null; firmName?: string; customValues?: Record; + fieldValues?: Record; }, ): string { const today = format(new Date(), "MMMM d, yyyy"); @@ -119,15 +120,42 @@ export function applyVariables( for (const [k, v] of Object.entries(replacements)) { out = out.split(k).join(v); } - // Custom variables like {{custom.mortgage_holder}} + // Custom case-field variables like {{custom.mortgage_holder}} if (ctx.customValues) { for (const [k, v] of Object.entries(ctx.customValues)) { out = out.split(`{{custom.${k}}}`).join(v ?? ""); } } + // Per-form fillable fields like {{field.tenant_name}} + if (ctx.fieldValues) { + for (const [k, v] of Object.entries(ctx.fieldValues)) { + out = out.split(`{{field.${k}}}`).join(v ?? ""); + } + } return out; } +// ---------- Per-template fillable fields ---------- +export type FormFieldType = + | "text" + | "textarea" + | "number" + | "date" + | "dropdown" + | "county" + | "client" + | "homeowner"; + +export interface FormFieldDef { + key: string; + label: string; + type: FormFieldType; + required?: boolean; + options?: string[]; // for dropdown + placeholder?: string; + default?: string; +} + export function fmtCurrency(n: number | string | null | undefined): string { const v = typeof n === "string" ? parseFloat(n) : (n ?? 0); return (Number.isFinite(v) ? v : 0).toLocaleString("en-US", {