Skip to content

Svelte 5 dynamic form building with formisch #154

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

Svelte 5 dynamic form building with formisch #154
flySewa wants to merge 5 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 blog post with an end-to-end example for building a dynamic invoice form in Svelte 5 using a schema-driven form approach.
    • Covers defining the invoice schema and validations, managing dynamic line items, computing totals live, resetting the form, and submitting validated/transformed data.
    • Includes practical guidance, what it enables, and recommended next steps for applying the pattern in real projects.

@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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8b51b52a-f465-4bb3-af3f-f19d6a62eee0

📥 Commits

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

📒 Files selected for processing (1)
  • website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx
✅ Files skipped from review due to trivial changes (1)
  • website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx

Walkthrough

This pull request adds a new MDX blog post at website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx describing a dynamic invoice form built with Formisch and Svelte 5. It covers Valibot schema validation, form creation with initial input, field and array wiring, reactive totals, submission handling, reset behavior, and closing guidance. No exported or public entities are changed.

Changes

File Change Summary
website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx New MDX blog post documenting a dynamic invoice form built with Formisch and Svelte 5

Sequence Diagram(s)

Not applicable.

Related Issues: None specified.

Related PRs: None specified.

Suggested labels: documentation, blog

Suggested reviewers: None specified.

🚥 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 clearly matches the new blog post about building a dynamic form in Svelte 5 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.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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

Parsing error: "parserOptions.project" has been provided for @typescript-eslint/parser.
The file was not found in any of the provided project(s): src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx


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 on lines +325 to +364
let invoiceInput = $derived.by(() => {
const taxRate = getInput(invoiceForm, {
path: ['taxRate']
});

const discount = getInput(invoiceForm, {
path: ['discount']
});

const lineItems = getInput(invoiceForm, {
path: ['lineItems']
});

return {
taxRate,
discount,
lineItems
};
});

let totals = $derived(calculateTotals(invoiceInput));

function calculateTotals(input) {
const subtotal = input.lineItems.reduce((sum, item) => {
return sum + Number(item.quantity) * Number(item.unitPrice);
}, 0);

const tax = subtotal * (Number(input.taxRate) / 100);

const discount = Number(input.discount);

const total = Math.max(subtotal + tax - discount, 0);

return {
subtotal,
tax,
discount,
total
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the target file around the cited lines
wc -l website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx
sed -n '300,390p' website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx

# Find the exact usages of getInput and calculateTotals in the file
rg -n "getInput|calculateTotals|Number\(" website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx

# Inspect nearby docs or examples for how getInput/form state is described in this repo
rg -n "getInput|validated output|raw input|onsubmit|FieldArray|insert|remove" website/src -g '*.mdx' -g '*.md'

Repository: open-circle/formisch

Length of output: 211


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE='website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx'

# Inspect the target file around the cited lines
wc -l "$FILE"
sed -n '300,390p' "$FILE"

# Find the exact usages of getInput and calculateTotals in the file
rg -n "getInput|calculateTotals|Number\(" "$FILE"

# Search related docs/examples in the repo
rg -n "getInput|validated output|raw input|onsubmit|FieldArray|insert|remove" website/src -g '*.mdx' -g '*.md'

Repository: open-circle/formisch

Length of output: 50379


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE='website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx'

# Show the schema section that defines taxRate/discount/lineItems types
sed -n '50,130p' "$FILE"

# Show the form-methods docs for getInput and handle submission
sed -n '1,130p' website/src/routes/(docs)/svelte/guides/(main-concepts)/form-methods/index.mdx
sed -n '1,120p' website/src/routes/(docs)/svelte/guides/(main-concepts)/handle-submission/index.mdx

# Show any direct getInput API docs in Svelte
fd -a 'getInput/index.mdx' website/src/routes/(docs)/svelte website/src/routes/(docs)/core

Repository: open-circle/formisch

Length of output: 2792


🏁 Script executed:

#!/bin/bash
set -euo pipefail

BLOG='website/src/routes/blog/(posts)/dynamic-invoice-form-svelte/index.mdx'
GETINPUT_DOC='website/src/routes/(docs)/svelte/guides/(main-concepts)/form-methods/index.mdx'
SUBMIT_DOC='website/src/routes/(docs)/svelte/guides/(main-concepts)/handle-submission/index.mdx'

# Relevant blog excerpt with line numbers
nl -ba "$BLOG" | sed -n '315,385p'

# Relevant docs excerpts
nl -ba "$GETINPUT_DOC" | sed -n '1,120p'
nl -ba "$SUBMIT_DOC" | sed -n '1,90p'

Repository: open-circle/formisch

Length of output: 198


Guard the live totals calculation against invalid in-progress values. getInput reads the current form input, so Number(...) can still produce NaN while a field is empty or mid-edit. Fall back to 0 for non-finite values, or derive the totals from validated output instead.

🤖 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 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.

@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.
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:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant