Option for automatically resetting validators
A potential solution for #903.
I think this is a more general solution than #726 but they both cover the same issue.
My assumption coming into Tanstack Form was that all previous validation errors would be cleared out when running the next validation but that doesn't seem to be the case.
So onMount returning an error means the error will always exist and onBlur returning an error is only cleared on the next blur event.
New behavior
When form.options.automaticallyResetValidators === true previous validation errors are cleared when running the validator,
else retain the previous behaviour.
Known problems
Calling .validateSync or .validateAsync will not cause the fields to be reset. These fields are however marked as @private so I think this is fine.
I think fixing this would also add a lot more complexity because the .validate method calls .validateSync and then .validateAsync, so we would need to know not to clear the errors that were just added by .validateSync in .validateAsync.
Questions
- [ ] One major question I have is what should the default be? Personally I think it should be
truebut this would be a breaking change.
☁️ Nx Cloud Report
CI is running/has finished running commands for commit eb01133c815d69e8b2b303f21761fa75c6b5f960. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this CI Pipeline Execution
✅ Successfully ran 2 targets
Sent with 💌 from NxCloud.
commit: eb01133
@tanstack/angular-form
pnpm add https://pkg.pr.new/@tanstack/angular-form@907
@tanstack/form-core
pnpm add https://pkg.pr.new/@tanstack/form-core@907
@tanstack/lit-form
pnpm add https://pkg.pr.new/@tanstack/lit-form@907
@tanstack/react-form
pnpm add https://pkg.pr.new/@tanstack/react-form@907
@tanstack/solid-form
pnpm add https://pkg.pr.new/@tanstack/solid-form@907
@tanstack/valibot-form-adapter
pnpm add https://pkg.pr.new/@tanstack/valibot-form-adapter@907
@tanstack/vue-form
pnpm add https://pkg.pr.new/@tanstack/vue-form@907
@tanstack/yup-form-adapter
pnpm add https://pkg.pr.new/@tanstack/yup-form-adapter@907
@tanstack/zod-form-adapter
pnpm add https://pkg.pr.new/@tanstack/zod-form-adapter@907
More templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-valibot
- @tanstack/form-example-angular-yup
- @tanstack/form-example-angular-zod
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-react-array
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-react-valibot
- @tanstack/form-example-react-yup
- @tanstack/form-example-react-zod
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-valibot
- @tanstack/form-example-solid-yup
- @tanstack/form-example-solid-zod
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-valibot
- @tanstack/form-example-vue-yup
- @tanstack/form-example-vue-zod
Codecov Report
Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
Project coverage is 88.48%. Comparing base (
5473bb8) to head (eb01133). Report is 155 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| packages/form-core/src/FieldApi.ts | 50.00% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #907 +/- ##
==========================================
- Coverage 91.55% 88.48% -3.07%
==========================================
Files 21 26 +5
Lines 900 938 +38
Branches 206 210 +4
==========================================
+ Hits 824 830 +6
- Misses 71 102 +31
- Partials 5 6 +1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Superseded by #726 but we can keep discussing in #1005 for improvements in the API