Skip to content

fix(Form): omit a record array from validation when all its records are empty - #135

Open
gdevenyi wants to merge 2 commits into
mainfrom
fix/record-array-empty-items
Open

gdevenyi wants to merge 2 commits into
mainfrom
fix/record-array-empty-items

Conversation

@gdevenyi

@gdevenyi gdevenyi commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A record array field adds one empty record when it is rendered. If the user did not fill it in, validation failed on that record.

 handleSubmit / revalidate
-  validationSchema.safeParseAsync(values)
+  validate()
validate()
  candidate = values without each record array where each value of each record is empty
              # empty = undefined, null, '', or an empty Set
  result = schema.parse(candidate)
  if result fails with an issue at an omitted record array   # the schema makes it required
    return schema.parse(values)                              # errors point at the item fields, as before
  return result
Form state Before After
Optional array, not filled in, item fields required Error at items.0.name Submits {}
Optional array, not filled in, item fields optional Submits { items: [{}] } Submits {}
Optional array, value typed, then cleared Error at items.0.name Submits {}
Optional array empty, a different field invalid Errors on that field and on items.0.name Error on that field only
Required array, not filled in Error at items.0.name No change
One record filled in, one empty Error at items.1.name No change

The form state does not change. Only the data given to the validation schema changes.

Evidence

  • Before: new record array tests in Form.test.tsx fail on main:
    × should submit an optional record array that was not filled in, although its fields are required
    × should not submit a record with all values empty in place of an omitted record array
    × should omit a record array where the only value was entered and then cleared
    
    After: pnpm test: 42 files, 253 tests pass. pnpm lint passes.

Merge Danger

Door: two-way

Blast Radius: submitted data

  • A form with an optional record array that the user did not fill in now submits no key for that field. Before, it submitted [{}] (optional item fields) or did not submit. A consumer that reads data.items[0] without a check must allow undefined.
  • A record with only a false checkbox value is not empty.
  • The schema can run two times on a submit that fails.

Closes #40

🤖 Generated with Claude Code

https://claude.ai/code/session_01W53iUP9ECVtoteopM7QtC7

…re empty

A record array field adds one empty record when it is rendered. If the
user did not fill it in, validation failed on the required fields of
that record, or the form submitted a record with no values.

Closes #40

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W53iUP9ECVtoteopM7QtC7
@gdevenyi
gdevenyi requested a review from joshunrau as a code owner November 10, 2026 04:22
Copilot AI balanced review requested due to automatic review settings November 10, 2026 04:22

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
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.

Cannot submit Record Array with empty item at index 0

2 participants