Skip to content

docs(form-core): update validateAllFields description#2117

Merged
harry-whorlow merged 1 commit intomainfrom
validate-all
Apr 10, 2026
Merged

docs(form-core): update validateAllFields description#2117
harry-whorlow merged 1 commit intomainfrom
validate-all

Conversation

@harry-whorlow
Copy link
Copy Markdown
Contributor

@harry-whorlow harry-whorlow commented Apr 10, 2026

Summary by CodeRabbit

  • Tests

    • Improved field validation test coverage with focused scenarios for on-change and on-submit validators, ensuring consistent error reporting across trigger phases.
  • Chores

    • Clarified validation-related documentation and applied small formatting adjustments for readability.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

Updated FormApi.validateAllFields JSDoc and added blank-line formatting inside its loop; tests refactored to replace one broad validation spec with two focused tests for field-level validators triggered onChange and onSubmit, with adjusted expected messages.

Changes

Cohort / File(s) Summary
Form API
packages/form-core/src/FormApi.ts
Updated JSDoc to state validateAllFields uses field-level validators and ignores form-level validators; added blank lines around the fieldInstance assignment and around each fieldValidationPromises.push(...) call. No behavioral changes.
Tests
packages/form-core/tests/FormApi.spec.ts
Replaced a single validation test with two focused tests covering field-level validators.onChange and validators.onSubmit; standardized expected error message to 'is required' and removed redundant assertions. Test-only changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibbled at whitespace, made the loop breathe light,
Two tests now hop gently — onChange and submit in sight,
Errors say "is required" with tidy, cheerful cheer,
A rabbit-approved patch, compact and clear. 🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, missing all required sections from the template including 'Changes', 'Checklist', and 'Release Impact'. Add a comprehensive description explaining the changes, validate the checklist items, and specify the release impact with a changeset if applicable.
Title check ⚠️ Warning The PR title 'docs(form-core): update validateAllFields description' describes documentation changes, but the actual changes include functional test refactoring with new test scenarios and validation logic assertions, not just documentation updates. Update the title to reflect the actual changes, such as 'test(form-core): refactor validateAllFields tests for field-level validators' or align the changes with the documentation-only scope described in the title.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch validate-all

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.

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Apr 10, 2026

View your CI Pipeline Execution ↗ for commit b0b50c7

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 1m 31s View ↗
nx run-many --target=build --exclude=examples/** ✅ Succeeded 32s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-10 17:16:11 UTC

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 10, 2026

🚀 Changeset Version Preview

2 package(s) bumped directly, 11 bumped as dependents.

🟨 Minor bumps

Package Version Reason
@tanstack/react-form 1.28.6 → 1.29.0 Changeset
@tanstack/svelte-form 1.28.6 → 1.29.0 Changeset
@tanstack/angular-form 1.28.6 → 1.29.0 Dependent
@tanstack/form-core 1.28.6 → 1.29.0 Dependent
@tanstack/react-form-nextjs 1.28.6 → 1.29.0 Dependent
@tanstack/react-form-remix 1.28.6 → 1.29.0 Dependent
@tanstack/react-form-start 1.28.6 → 1.29.0 Dependent
@tanstack/solid-form 1.28.6 → 1.29.0 Dependent
@tanstack/vue-form 1.28.6 → 1.29.0 Dependent

🟩 Patch bumps

Package Version Reason
@tanstack/form-devtools 0.2.20 → 0.2.21 Dependent
@tanstack/lit-form 1.23.26 → 1.23.27 Dependent
@tanstack/react-form-devtools 0.2.20 → 0.2.21 Dependent
@tanstack/solid-form-devtools 0.2.20 → 0.2.21 Dependent

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 10, 2026

More templates

@tanstack/angular-form

npm i https://pkg.pr.new/@tanstack/angular-form@2117

@tanstack/form-core

npm i https://pkg.pr.new/@tanstack/form-core@2117

@tanstack/form-devtools

npm i https://pkg.pr.new/@tanstack/form-devtools@2117

@tanstack/lit-form

npm i https://pkg.pr.new/@tanstack/lit-form@2117

@tanstack/react-form

npm i https://pkg.pr.new/@tanstack/react-form@2117

@tanstack/react-form-devtools

npm i https://pkg.pr.new/@tanstack/react-form-devtools@2117

@tanstack/react-form-nextjs

npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2117

@tanstack/react-form-remix

npm i https://pkg.pr.new/@tanstack/react-form-remix@2117

@tanstack/react-form-start

npm i https://pkg.pr.new/@tanstack/react-form-start@2117

@tanstack/solid-form

npm i https://pkg.pr.new/@tanstack/solid-form@2117

@tanstack/solid-form-devtools

npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2117

@tanstack/svelte-form

npm i https://pkg.pr.new/@tanstack/svelte-form@2117

@tanstack/vue-form

npm i https://pkg.pr.new/@tanstack/vue-form@2117

commit: b0b50c7

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/form-core/tests/FormApi.spec.ts (1)

2020-2064: Field-level “all fields” tests currently validate only one mounted field.

The test titles say “all fields,” but only firstName is mounted/asserted in both cases. Consider mounting lastName too (or rename tests) so iteration regressions are caught.

♻️ Suggested test hardening
   it('should validate all fields consistently - field level onChange validators', async () => {
     const form = new FormApi({
       defaultValues: {
         firstName: '',
         lastName: '',
       },
     })

-    const field = new FieldApi({
+    const firstNameField = new FieldApi({
       form,
       name: 'firstName',
       validators: {
         onChange: ({ value }) => (value.length > 0 ? undefined : 'is required'),
       },
     })
+    const lastNameField = new FieldApi({
+      form,
+      name: 'lastName',
+      validators: {
+        onChange: ({ value }) => (value.length > 0 ? undefined : 'is required'),
+      },
+    })

     form.mount()
-    field.mount()
+    firstNameField.mount()
+    lastNameField.mount()

     await form.validateAllFields('change')
-    expect(field.getMeta().errorMap.onChange).toEqual('is required')
+    expect(firstNameField.getMeta().errorMap.onChange).toEqual('is required')
+    expect(lastNameField.getMeta().errorMap.onChange).toEqual('is required')
   })

   it('should validate all fields consistently - field level onSubmit validators', async () => {
     const form = new FormApi({
       defaultValues: {
         firstName: '',
         lastName: '',
       },
     })

-    const field = new FieldApi({
+    const firstNameField = new FieldApi({
       form,
       name: 'firstName',
       validators: {
         onSubmit: ({ value }) => (value.length > 0 ? undefined : 'is required'),
       },
     })
+    const lastNameField = new FieldApi({
+      form,
+      name: 'lastName',
+      validators: {
+        onSubmit: ({ value }) => (value.length > 0 ? undefined : 'is required'),
+      },
+    })

     form.mount()
-    field.mount()
+    firstNameField.mount()
+    lastNameField.mount()

     await form.validateAllFields('submit')
-    expect(field.getMeta().errorMap.onSubmit).toEqual('is required')
+    expect(firstNameField.getMeta().errorMap.onSubmit).toEqual('is required')
+    expect(lastNameField.getMeta().errorMap.onSubmit).toEqual('is required')
   })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/form-core/tests/FormApi.spec.ts` around lines 2020 - 2064, The tests
for validateAllFields currently only mount and assert the 'firstName' FieldApi,
so add a second FieldApi for 'lastName' (using FieldApi with form, name:
'lastName', and the same validators) and call mount() on it before await
form.validateAllFields('change'|'submit'), then assert that
lastName.getMeta().errorMap.onChange (or .onSubmit) equals 'is required';
alternatively, rename the test titles if you intentionally only want to exercise
a single field. Ensure references to FormApi, FieldApi, validateAllFields,
mount, and getMeta are used to locate and update the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/form-core/tests/FormApi.spec.ts`:
- Around line 2020-2064: The tests for validateAllFields currently only mount
and assert the 'firstName' FieldApi, so add a second FieldApi for 'lastName'
(using FieldApi with form, name: 'lastName', and the same validators) and call
mount() on it before await form.validateAllFields('change'|'submit'), then
assert that lastName.getMeta().errorMap.onChange (or .onSubmit) equals 'is
required'; alternatively, rename the test titles if you intentionally only want
to exercise a single field. Ensure references to FormApi, FieldApi,
validateAllFields, mount, and getMeta are used to locate and update the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1283b8d5-7804-432a-987a-8afc2f7e84d2

📥 Commits

Reviewing files that changed from the base of the PR and between 070caca and 09fff77.

📒 Files selected for processing (2)
  • packages/form-core/src/FormApi.ts
  • packages/form-core/tests/FormApi.spec.ts

@harry-whorlow
Copy link
Copy Markdown
Contributor Author

relates to #1208

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/form-core/tests/FormApi.spec.ts (1)

1971-1992: Add a regression guard that form-level validators are not invoked here.

These tests currently verify field-level errors only. A small negative assertion would lock the intended validateAllFields contract more tightly.

Suggested test hardening
   it('should validate all fields consistently - field level onSubmit validators', async () => {
+    const formOnSubmit = vi.fn().mockReturnValue('form-level error')
     const form = new FormApi({
       defaultValues: {
         firstName: '',
         lastName: '',
       },
+      validators: {
+        onSubmit: formOnSubmit,
+      },
     })

     const field = new FieldApi({
       form,
       name: 'firstName',
       validators: {
         onSubmit: ({ value }) => (value.length > 0 ? undefined : 'is required'),
       },
     })

     form.mount()
     field.mount()

     await form.validateAllFields('submit')
     expect(field.getMeta().errorMap.onSubmit).toEqual('is required')
+    expect(formOnSubmit).not.toHaveBeenCalled()
   })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/form-core/tests/FormApi.spec.ts` around lines 1971 - 1992, Add a
negative assertion to ensure form-level validators are not invoked in this test:
after calling form.validateAllFields('submit') and asserting the field error,
assert that form-level validator state (e.g., any
form.getMeta().errorMap.onSubmit or a mock form-level validator call counter)
remains undefined/unchanged so the test guarantees only FieldApi.onSubmit ran;
locate FormApi, FieldApi, and validateAllFields in the test to add this check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/form-core/tests/FormApi.spec.ts`:
- Around line 1971-1992: Add a negative assertion to ensure form-level
validators are not invoked in this test: after calling
form.validateAllFields('submit') and asserting the field error, assert that
form-level validator state (e.g., any form.getMeta().errorMap.onSubmit or a mock
form-level validator call counter) remains undefined/unchanged so the test
guarantees only FieldApi.onSubmit ran; locate FormApi, FieldApi, and
validateAllFields in the test to add this check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 81096b9d-0b5c-42dd-898d-7131765763e1

📥 Commits

Reviewing files that changed from the base of the PR and between 09fff77 and b0b50c7.

📒 Files selected for processing (2)
  • packages/form-core/src/FormApi.ts
  • packages/form-core/tests/FormApi.spec.ts
✅ Files skipped from review due to trivial changes (1)
  • packages/form-core/src/FormApi.ts

@sentry
Copy link
Copy Markdown

sentry bot commented Apr 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.25%. Comparing base (6892ed0) to head (b0b50c7).
⚠️ Report is 164 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2117      +/-   ##
==========================================
- Coverage   90.35%   90.25%   -0.10%     
==========================================
  Files          38       49      +11     
  Lines        1752     2043     +291     
  Branches      444      532      +88     
==========================================
+ Hits         1583     1844     +261     
- Misses        149      179      +30     
  Partials       20       20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@harry-whorlow harry-whorlow changed the title fix(form-core): validateAllFields not validating with form level vali… docs(form-core): update validateAllFields description Apr 10, 2026
@harry-whorlow harry-whorlow merged commit 644b558 into main Apr 10, 2026
9 checks passed
@harry-whorlow harry-whorlow deleted the validate-all branch April 10, 2026 17:39
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