[PR #1615] [MERGED] feat: allow fields prefill when generating a document from a template #1753

Closed
opened 2026-02-26 20:30:55 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/documenso/documenso/pull/1615
Author: @catalinpit
Created: 1/29/2025
Status: Merged
Merged: 3/5/2025
Merged by: @Mythie

Base: mainHead: feat/prefill-fields-when-generating-doc-from-template


📝 Commits (10+)

  • d25d67f feat: allow fields prefill when generating a document from a template
  • 1ce8eb4 chore: fix select component
  • 86b649a chore: fix select components
  • cbe11ee Merge branch 'main' into feat/prefill-fields-when-generating-doc-from-template
  • b1f54d6 chore: implement part of pr feedback
  • ce73b57 chore: implement the other part of the feedback
  • 6de2bee chore: make fieldMeta required
  • 4a29613 chore: make fieldMeta required
  • 9d3a2a5 Merge branch 'main' into feat/prefill-fields-when-generating-doc-from-template
  • c0db055 Merge branch 'main' into feat/prefill-fields-when-generating-doc-from-template

📊 Changes

11 files changed (+1521 additions, -19 deletions)

View changed files

📝 package-lock.json (+15 -0)
📝 packages/api/v1/implementation.ts (+1 -0)
📝 packages/api/v1/schema.ts (+2 -1)
packages/app-tests/e2e/api/v1/template-field-prefill.spec.ts (+612 -0)
packages/app-tests/e2e/api/v2/template-field-prefill.spec.ts (+600 -0)
📝 packages/lib/server-only/template/create-document-from-template.ts (+237 -14)
📝 packages/lib/types/field-meta.ts (+36 -0)
📝 packages/trpc/server/template-router/router.ts (+3 -1)
📝 packages/trpc/server/template-router/schema.ts (+2 -0)
📝 packages/ui/primitives/document-flow/field-items-advanced-settings/dropdown-field.tsx (+6 -2)
📝 packages/ui/primitives/document-flow/field-items-advanced-settings/text-field.tsx (+7 -1)

📄 Description

Description

V1 API Prefill Values

https://github.com/user-attachments/assets/92d5cd75-9048-4eb1-8dea-8c55e563febb

V2 API Prefill Values

https://github.com/user-attachments/assets/07401698-a04a-4d39-9649-61bac81795ef

Changes Made

The new change allows API users to pre-fill fields with values by passing the data in the request body. Example body for V2 API endpoint /api/v2-beta/template/use:

{
    "templateId": 1,
    "recipients": [
        {
            "id": 1,
            "email": "signer1@mail.com",
            "name": "Signer 1"
        },
        {
            "id": 2,
            "email": "signer2@mail.com",
            "name": "Signer 2"
        }
    ],
    "prefillValues": [
        {
            "id": 14,
            "fieldMeta": {
                "type": "text",
                "label": "my label",
                "placeholder": "text placeholder test",
                "text": "auto-sign value",
                "characterLimit": 25,
                "textAlign": "right",
                "fontSize": 94,
                "required": true
            }
        },
        {
            "id": 15,
            "fieldMeta": {
                "type": "radio",
                "label": "radio label",
                "placeholder": "new radio placeholder",
                "required": false,
                "readOnly": true,
                "values": [
                    {
                        "id": 2,
                        "checked": true,
                        "value": "radio val 1"
                    },
                    {
                        "id": 3,
                        "checked": false,
                        "value": "radio val 2"
                    }
                ]
            }
        },
        {
            "id": 16,
            "fieldMeta": {
                "type": "dropdown",
                "label": "dropdown label",
                "placeholder": "DD placeholder",
                "required": false,
                "readOnly": false,
                "values": [
                    {
                        "value": "option 1"
                    },
                    {
                        "value": "option 2"
                    },
                    {
                        "value": "option 3"
                    }
                ],
                "defaultValue": "option 2"
            }
        }
    ],
    "distributeDocument": false,
    "customDocumentDataId": ""
}

Testing Performed

I tested the changes by making requests via both the V1 and V2 APIs with various values.

Checklist

  • I have tested these changes locally and they work as expected.
  • I have added/updated tests that prove the effectiveness of these changes.
  • I have updated the documentation to reflect these changes, if applicable.
  • I have followed the project's coding style guidelines.
  • I have addressed the code review feedback from the previous submission, if applicable.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/documenso/documenso/pull/1615 **Author:** [@catalinpit](https://github.com/catalinpit) **Created:** 1/29/2025 **Status:** ✅ Merged **Merged:** 3/5/2025 **Merged by:** [@Mythie](https://github.com/Mythie) **Base:** `main` ← **Head:** `feat/prefill-fields-when-generating-doc-from-template` --- ### 📝 Commits (10+) - [`d25d67f`](https://github.com/documenso/documenso/commit/d25d67f7cea5a9d811b179fa65835b96fce77f26) feat: allow fields prefill when generating a document from a template - [`1ce8eb4`](https://github.com/documenso/documenso/commit/1ce8eb43b1f817f23644fa8af95d59cc10f02be1) chore: fix select component - [`86b649a`](https://github.com/documenso/documenso/commit/86b649a6748ac528fb2eecf6113141c94ac5089e) chore: fix select components - [`cbe11ee`](https://github.com/documenso/documenso/commit/cbe11ee08969536594500b0514a36ef9eb3ee00b) Merge branch 'main' into feat/prefill-fields-when-generating-doc-from-template - [`b1f54d6`](https://github.com/documenso/documenso/commit/b1f54d6ae8cee1fbb0d47e21847d5567826f9844) chore: implement part of pr feedback - [`ce73b57`](https://github.com/documenso/documenso/commit/ce73b57926c5b50f2c356ff1ecf0d9c4ec3b0325) chore: implement the other part of the feedback - [`6de2bee`](https://github.com/documenso/documenso/commit/6de2beecbde3a975013beea80c18bffde6cedfbb) chore: make fieldMeta required - [`4a29613`](https://github.com/documenso/documenso/commit/4a29613ab02bb2bb75c71f9198fca1df9e9cdad2) chore: make fieldMeta required - [`9d3a2a5`](https://github.com/documenso/documenso/commit/9d3a2a5a5fb4213fc52f545e0b669b09d671d3fd) Merge branch 'main' into feat/prefill-fields-when-generating-doc-from-template - [`c0db055`](https://github.com/documenso/documenso/commit/c0db0552e5e356ce96a804f6a2cde7e3e112f932) Merge branch 'main' into feat/prefill-fields-when-generating-doc-from-template ### 📊 Changes **11 files changed** (+1521 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `package-lock.json` (+15 -0) 📝 `packages/api/v1/implementation.ts` (+1 -0) 📝 `packages/api/v1/schema.ts` (+2 -1) ➕ `packages/app-tests/e2e/api/v1/template-field-prefill.spec.ts` (+612 -0) ➕ `packages/app-tests/e2e/api/v2/template-field-prefill.spec.ts` (+600 -0) 📝 `packages/lib/server-only/template/create-document-from-template.ts` (+237 -14) 📝 `packages/lib/types/field-meta.ts` (+36 -0) 📝 `packages/trpc/server/template-router/router.ts` (+3 -1) 📝 `packages/trpc/server/template-router/schema.ts` (+2 -0) 📝 `packages/ui/primitives/document-flow/field-items-advanced-settings/dropdown-field.tsx` (+6 -2) 📝 `packages/ui/primitives/document-flow/field-items-advanced-settings/text-field.tsx` (+7 -1) </details> ### 📄 Description ## Description ### V1 API Prefill Values https://github.com/user-attachments/assets/92d5cd75-9048-4eb1-8dea-8c55e563febb ### V2 API Prefill Values https://github.com/user-attachments/assets/07401698-a04a-4d39-9649-61bac81795ef ## Changes Made The new change allows API users to pre-fill fields with values by passing the data in the request body. Example body for V2 API endpoint `/api/v2-beta/template/use`: ```json { "templateId": 1, "recipients": [ { "id": 1, "email": "signer1@mail.com", "name": "Signer 1" }, { "id": 2, "email": "signer2@mail.com", "name": "Signer 2" } ], "prefillValues": [ { "id": 14, "fieldMeta": { "type": "text", "label": "my label", "placeholder": "text placeholder test", "text": "auto-sign value", "characterLimit": 25, "textAlign": "right", "fontSize": 94, "required": true } }, { "id": 15, "fieldMeta": { "type": "radio", "label": "radio label", "placeholder": "new radio placeholder", "required": false, "readOnly": true, "values": [ { "id": 2, "checked": true, "value": "radio val 1" }, { "id": 3, "checked": false, "value": "radio val 2" } ] } }, { "id": 16, "fieldMeta": { "type": "dropdown", "label": "dropdown label", "placeholder": "DD placeholder", "required": false, "readOnly": false, "values": [ { "value": "option 1" }, { "value": "option 2" }, { "value": "option 3" } ], "defaultValue": "option 2" } } ], "distributeDocument": false, "customDocumentDataId": "" } ``` ## Testing Performed I tested the changes by making requests via both the V1 and V2 APIs with various values. ## Checklist <!--- Please check the boxes that apply to this pull request. --> <!--- You can add or remove items as needed. --> - [x] I have tested these changes locally and they work as expected. - [ ] I have added/updated tests that prove the effectiveness of these changes. - [ ] I have updated the documentation to reflect these changes, if applicable. - [x] I have followed the project's coding style guidelines. - [ ] I have addressed the code review feedback from the previous submission, if applicable. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 20:30:55 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/documenso#1753
No description provided.