Skip to content

feat(utils): add form utilities#20

Merged
maitamdev merged 1 commit intomainfrom
feat/form-utils
Mar 4, 2026
Merged

feat(utils): add form utilities#20
maitamdev merged 1 commit intomainfrom
feat/form-utils

Conversation

@maitamdev
Copy link
Copy Markdown
Owner

@maitamdev maitamdev commented Mar 4, 2026

Form serialization, dirty checking, and error display utilities.


Summary by cubic

Add reusable form utilities for serializing values, checking dirty state, resetting forms, and showing field errors. This reduces boilerplate and improves accessibility with aria-invalid.

  • New Features
    • serializeForm(form): build a key-value map from FormData.
    • resetForm(form): reset all fields.
    • isFormDirty(form, original): compare current vs. original values.
    • setFormErrors(errors): mark fields aria-invalid and populate {field}-error text.

Written for commit 082b9eb. Summary will update on new commits.

Co-authored-by: DHV Team <dhvteam@users.noreply.github.com>
@maitamdev maitamdev merged commit b3a0753 into main Mar 4, 2026
1 of 3 checks passed
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dhv-guiding-light Building Building Preview, Comment Mar 4, 2026 7:20pm

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 4, 2026

Warning

Rate limit exceeded

@maitamdev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 48 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 49ec07a8-cbb7-4b9b-af04-ec9c1d70d21e

📥 Commits

Reviewing files that changed from the base of the PR and between 4d7b11d and 082b9eb.

📒 Files selected for processing (1)
  • src/utils/formUtils.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/form-utils

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 and usage tips.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

2 issues found across 1 file

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="src/utils/formUtils.ts">

<violation number="1" location="src/utils/formUtils.ts:11">
P2: Dirty-check logic misses fields that exist only in current form values, causing false negatives.</violation>

<violation number="2" location="src/utils/formUtils.ts:15">
P1: The generated CSS selector is malformed, which can throw at runtime and prevent form errors from being rendered.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

}
export function setFormErrors(errors: Record<string, string>): void {
Object.entries(errors).forEach(([field, message]) => {
const el = document.querySelector('[name=""' + field + '""]');
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

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

P1: The generated CSS selector is malformed, which can throw at runtime and prevent form errors from being rendered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/formUtils.ts, line 15:

<comment>The generated CSS selector is malformed, which can throw at runtime and prevent form errors from being rendered.</comment>

<file context>
@@ -0,0 +1,20 @@
+}
+export function setFormErrors(errors: Record<string, string>): void {
+  Object.entries(errors).forEach(([field, message]) => {
+    const el = document.querySelector('[name=""' + field + '""]');
+    if (el) el.setAttribute('aria-invalid', 'true');
+    const errEl = document.getElementById(field + '-error');
</file context>
Fix with Cubic

export function resetForm(form: HTMLFormElement): void { form.reset(); }
export function isFormDirty(form: HTMLFormElement, originalValues: Record<string, string>): boolean {
const currentValues = serializeForm(form);
return Object.keys(originalValues).some(key => originalValues[key] !== currentValues[key]);
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 4, 2026

Choose a reason for hiding this comment

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

P2: Dirty-check logic misses fields that exist only in current form values, causing false negatives.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/formUtils.ts, line 11:

<comment>Dirty-check logic misses fields that exist only in current form values, causing false negatives.</comment>

<file context>
@@ -0,0 +1,20 @@
+export function resetForm(form: HTMLFormElement): void { form.reset(); }
+export function isFormDirty(form: HTMLFormElement, originalValues: Record<string, string>): boolean {
+  const currentValues = serializeForm(form);
+  return Object.keys(originalValues).some(key => originalValues[key] !== currentValues[key]);
+}
+export function setFormErrors(errors: Record<string, string>): void {
</file context>
Fix with Cubic

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant