Skip to content

Svelte 5 dynamic form building with formisch #154

Open
flySewa wants to merge 8 commits into
open-circle:mainfrom
flySewa:main
Open

Svelte 5 dynamic form building with formisch #154
flySewa wants to merge 8 commits into
open-circle:mainfrom
flySewa:main

Conversation

@flySewa

@flySewa flySewa commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Documentation
    • Added a new SvelteKit blog post with an end-to-end example for building a dynamic invoice form in Svelte 5 using a schema-driven approach.
    • Covers validation and transformations, dynamic line items, live total calculations, form reset, and submitting validated/transformed output.
    • Includes practical guidance on when to use the pattern, plus links to related architecture and comparison materials.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. documentation Improvements or additions to documentation labels Jul 4, 2026
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This pull request adds a standalone Svelte 5 invoice form example using Formisch and Valibot, with schema-driven validation, transformed numeric output, nested fields, dynamic line items, reactive totals, submission handling, reset behavior, styling, and project configuration. It also adds an MDX blog post documenting the implementation from schema setup through submission and closing guidance.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: a Svelte 5 dynamic form example and docs built with Formisch.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@website/src/routes/blog/`(posts)/dynamic-invoice-form-svelte/index.mdx:
- Around line 389-397: The submit handler currently loses the schema-derived
type at the boundary, so update submitInvoice to explicitly type its argument
using InvoiceOutput or SubmitHandler<typeof InvoiceSchema>. Keep the typing
aligned with the typed onsubmit pattern used in the example, and preserve the
existing submittedInvoice assignment and logging inside submitInvoice.
- Around line 325-364: The live totals computation in calculateTotals is still
using raw getInput values, so Number(...) can yield NaN while fields are empty
or mid-edit. Update invoiceInput/totals so invalid or non-finite inputs fall
back to 0 before arithmetic, or switch calculateTotals to consume validated form
output instead of the in-progress input values. Keep the fix centered around
calculateTotals, invoiceInput, and getInput so the derived totals remain stable
during editing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 86239cde-0515-4b06-8003-b3835a94537a

📥 Commits

Reviewing files that changed from the base of the PR and between 12e2bbb and 16cac43.

📒 Files selected for processing (1)
  • website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx

Comment thread website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx Outdated
flySewa added 2 commits July 4, 2026 19:08
Expanded the explanation of Formisch to emphasize its schema-native approach, benefits for complex forms, and integration with Svelte 5 reactivity. Clarified its headless nature and future support for SvelteKit.
@fabian-hiller

Copy link
Copy Markdown
Member

Should we add the example as a Vite based Svelte project in examples/svelte-invoice-form to our repo?

@flySewa

flySewa commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Should we add the example as a Vite based Svelte project in examples/svelte-invoice-form to our repo?

Sure, I can do that. I haven't added an example to the repo before though. Should I copy the StackBlitz project as-is into examples/svelte-invoice-form, or is there an existing example I should use as a template?

@fabian-hiller

Copy link
Copy Markdown
Member

Yes you can do that. But I can also take care of it if you prefer that. Let's plan this post for early next week.

@dosubot dosubot Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 13, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/svelte-invoice-form/README.md`:
- Around line 33-39: Update the project structure tree in the README to
reference src/schema.ts instead of src/lib/schema.ts, matching the actual schema
file location.

In `@examples/svelte-invoice-form/src/App.svelte`:
- Line 82: Remove the console.log statement for submitted invoice output in the
App submission handler, and remove the corresponding UI claim that invoice data
is logged. Do not log client or invoice data elsewhere in this flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 836c9729-000a-4d5b-9dbe-f9459b995934

📥 Commits

Reviewing files that changed from the base of the PR and between e0088f0 and c8447d1.

⛔ Files ignored due to path filters (1)
  • examples/svelte-invoice-form/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (13)
  • examples/svelte-invoice-form/.gitignore
  • examples/svelte-invoice-form/README.md
  • examples/svelte-invoice-form/index.html
  • examples/svelte-invoice-form/package.json
  • examples/svelte-invoice-form/src/App.svelte
  • examples/svelte-invoice-form/src/app.css
  • examples/svelte-invoice-form/src/main.ts
  • examples/svelte-invoice-form/src/schema.ts
  • examples/svelte-invoice-form/src/vite-env.d.ts
  • examples/svelte-invoice-form/svelte.config.js
  • examples/svelte-invoice-form/tsconfig.json
  • examples/svelte-invoice-form/vite.config.ts
  • website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx

Comment thread examples/svelte-invoice-form/README.md

const submitInvoice: SubmitHandler<typeof InvoiceSchema> = (output) => {
submittedInvoice = output;
console.log('Invoice submitted:', output);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🟡 Minor | ⚡ Quick win

Avoid logging client and invoice data to the console.

The output contains client names, email addresses, and invoice details. Remove the debug log and the corresponding UI claim.

   const submitInvoice: SubmitHandler<typeof InvoiceSchema> = (output) => {
     submittedInvoice = output;
-    console.log('Invoice submitted:', output);
   };
-        Typed, validated schema output (also logged to the console).
+        Typed, validated schema output.

Also applies to: 383-385

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/svelte-invoice-form/src/App.svelte` at line 82, Remove the
console.log statement for submitted invoice output in the App submission
handler, and remove the corresponding UI claim that invoice data is logged. Do
not log client or invoice data elsewhere in this flow.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 14 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="examples/svelte-invoice-form/src/app.css">

<violation number="1" location="examples/svelte-invoice-form/src/app.css:2">
P2: Form controls and section boundaries are barely distinguishable from their white surfaces because `--border` has very low contrast. A darker border token meeting at least 3:1 contrast against both `--surface` and `--bg` would make the fields and buttons identifiable for users with low vision.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread examples/svelte-invoice-form/src/app.css
@@ -0,0 +1,205 @@
:root {
--border: #e2e8f0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Form controls and section boundaries are barely distinguishable from their white surfaces because --border has very low contrast. A darker border token meeting at least 3:1 contrast against both --surface and --bg would make the fields and buttons identifiable for users with low vision.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At examples/svelte-invoice-form/src/app.css, line 2:

<comment>Form controls and section boundaries are barely distinguishable from their white surfaces because `--border` has very low contrast. A darker border token meeting at least 3:1 contrast against both `--surface` and `--bg` would make the fields and buttons identifiable for users with low vision.</comment>

<file context>
@@ -0,0 +1,205 @@
+:root {
+  --border: #e2e8f0;
+  --muted: #64748b;
+  --text: #0f172a;
</file context>

Comment thread examples/svelte-invoice-form/package.json
Comment thread examples/svelte-invoice-form/src/schema.ts
Comment thread examples/svelte-invoice-form/README.md Outdated
Comment thread examples/svelte-invoice-form/src/App.svelte
Comment thread examples/svelte-invoice-form/src/schema.ts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx (1)

322-347: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Still unaddressed: guard live totals against NaN from in-progress input values.

This was previously flagged and remains open. getInput returns raw input state, so Number(...) can produce NaN if a field value is undefined or a non-numeric string mid-edit. Consider falling back to 0 for non-finite values, e.g. Number(value) || 0 or isFinite(Number(value)) ? Number(value) : 0.

Also applies to: 355-361

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@website/src/routes/blog/`(posts)/dynamic-invoice-form-svelte/index.mdx around
lines 322 - 347, Update calculateTotals to normalize every numeric value from
invoiceInput—line item quantity and unitPrice, taxRate, and discount—before
arithmetic, falling back to 0 for undefined, non-numeric, or otherwise
non-finite values so live totals never become NaN.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@website/src/routes/blog/`(posts)/dynamic-invoice-form-svelte/index.mdx:
- Around line 322-347: Update calculateTotals to normalize every numeric value
from invoiceInput—line item quantity and unitPrice, taxRate, and discount—before
arithmetic, falling back to 0 for undefined, non-numeric, or otherwise
non-finite values so live totals never become NaN.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1e3333e2-b979-4337-a39f-c64f1c672359

📥 Commits

Reviewing files that changed from the base of the PR and between c8447d1 and 8956b5f.

📒 Files selected for processing (1)
  • website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants