Skip to content

Conversation

LeCarbonator
Copy link
Contributor

This meta property is a shortened alternative to checking
field.state.meta.errors.length === 0. Since FormApi already has this
property, a FieldApi variant wouldn't hurt to be more clear.

This PR is based on Balastrong's suggestion on Discord.

Copy link

nx-cloud bot commented Apr 16, 2025

View your CI Pipeline Execution ↗ for commit c7572f0.

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

☁️ Nx Cloud last updated this comment at 2025-04-29 07:37:04 UTC

Copy link

pkg-pr-new bot commented Apr 16, 2025

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/lit-form

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

@tanstack/react-form

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

@tanstack/solid-form

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

@tanstack/vue-form

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

@tanstack/svelte-form

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

commit: c7572f0

@LeCarbonator LeCarbonator marked this pull request as draft April 16, 2025 19:07
@LeCarbonator
Copy link
Contributor Author

For some reason, refactoring this FormApi check fails horribly. Does someone know why?

- const isFieldsValid = !fieldMetaValues.some(
-           (field) =>
-             field?.errorMap &&
-             isNonEmptyArray(Object.values(field.errorMap).filter(Boolean)),
-         )

+ const isFieldsValid = fieldMetaValues.every(
+          (field) => field === undefined || field.isValid,
+        )

@Pascalmh
Copy link
Contributor

Pascalmh commented Apr 16, 2025

Does this work?

const isFieldsValid = fieldMetaValues
  .filter(Boolean)
  .every((field) => field.isValid)

@LeCarbonator
Copy link
Contributor Author

No, but it's clear that the meta needs to be adjusted in some places. I'll tinker with it tomorrow.

@LeCarbonator
Copy link
Contributor Author

It's wild. I added checks wherever field errors or errorMap were tested for and it worked no problem. However, trying to rewrite isFieldsValid to use this boolean fails at 8 locations. I'll have to spend some more time figuring out how store works or something related to that

@LeCarbonator
Copy link
Contributor Author

Does this work?

const isFieldsValid = fieldMetaValues
  .filter(Boolean)
  .every((field) => field.isValid)

It works now! This code wasn't the problem, but my implementation of isValid.

Copy link

codecov bot commented Apr 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.98%. Comparing base (bfb8c42) to head (c7572f0).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1422   +/-   ##
=======================================
  Coverage   88.97%   88.98%           
=======================================
  Files          31       31           
  Lines        1397     1398    +1     
  Branches      353      353           
=======================================
+ Hits         1243     1244    +1     
  Misses        137      137           
  Partials       17       17           

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

this is a shortened counterpart to checking
field.state.meta.errors.length > 0
@LeCarbonator LeCarbonator marked this pull request as ready for review April 18, 2025 10:00
Copy link
Member

@Balastrong Balastrong left a comment

Choose a reason for hiding this comment

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

That's great, thank you!

@Balastrong Balastrong merged commit 443d270 into TanStack:main Apr 29, 2025
6 checks passed
@LeCarbonator LeCarbonator deleted the field-meta-is-valid branch April 29, 2025 11:24
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.

3 participants