Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/utils/formUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Form utility helpers
export function serializeForm(form: HTMLFormElement): Record<string, string> {
const data: Record<string, string> = {};
const formData = new FormData(form);
formData.forEach((value, key) => { data[key] = value.toString(); });
return data;
}
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

}
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

if (el) el.setAttribute('aria-invalid', 'true');
const errEl = document.getElementById(field + '-error');
if (errEl) errEl.textContent = message;
});
}
Loading