form icon indicating copy to clipboard operation
form copied to clipboard

Option for automatically resetting validators

Open oscartbeaumont opened this issue 1 year ago • 3 comments

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 true but this would be a breaking change.

oscartbeaumont avatar Aug 17 '24 03:08 oscartbeaumont

☁️ 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.

nx-cloud[bot] avatar Aug 17 '24 03:08 nx-cloud[bot]

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

Open in Stackblitz

More templates

pkg-pr-new[bot] avatar Aug 17 '24 03:08 pkg-pr-new[bot]

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.

codecov[bot] avatar Aug 17 '24 04:08 codecov[bot]

Superseded by #726 but we can keep discussing in #1005 for improvements in the API

Balastrong avatar Nov 04 '24 20:11 Balastrong