-
-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(form-core): clear previous invalid sync validation errors on FormApi #1157
fix(form-core): clear previous invalid sync validation errors on FormApi #1157
Conversation
Thanks! @harry-whorlow that makes sense. Cool, I just ran test:ci and got a successful pass: |
View your CI Pipeline Execution ↗ for commit f230dcd.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1157 +/- ##
==========================================
+ Coverage 88.42% 88.50% +0.07%
==========================================
Files 27 27
Lines 1210 1218 +8
Branches 320 322 +2
==========================================
+ Hits 1070 1078 +8
Misses 125 125
Partials 15 15 ☔ View full report in Codecov by Sentry. |
Just be aware that now the ci is running, it'll add a commit to your branch. This commit will contain generated docs and type definitions. So git pull before you push again, as your remote will be one commit ahead from your local. Good luck with the pr 🫡 |
Another approach I thought of was to update the errorMap type to store the validation source. This would allow us to know which errors should be clearable at the form level once stale. This would be quite a breaking change though so unsure... Something like changing the current type below to: export type ValidationErrorMap = {
[K in ValidationErrorMapKeys]?: ValidationError
} export type ValidationErrorMap = {
[K in ValidationErrorMapKeys]?: { error: ValidationError, source: ValidationSource }
} We already have a type for Validation Source here. Since @crutchcorn is already reworking the ValidationErrors maybe something like this could be considered, else I'm not sure how else to know which errors on the map came from the form and should be cleared. My current approach works because we create essentially a form sourced error map for each field within prevFieldsErrorMap |
… no longer valid When performing sync validation, ensure that previous field errors are cleared if they are no longer present in the new validation result. This prevents stale validation errors from persisting in the form state.
accept incoming changes
… FormErrorMapFromValidator type
31b9c6a
to
f2560ea
Compare
Resolved conflicts and updated type for prevFieldsErrorMap to uptake new types: /**
* @private map of errors originated from form level validators
*/
prevFieldsErrorMap: FormErrorMapFromValidator<
TFormData,
TOnMount,
TOnChange,
TOnChangeAsync,
TOnBlur,
TOnBlurAsync,
TOnSubmit,
TOnSubmitAsync
> = {} Moved existing code for clearing errorMap on for submit when user edits field up into the same batch call. |
Hey @Balastrong, just checking in—let me know if there's anything else I need to do for this PR to be merged, or if it's just a matter of waiting. Appreciate your time! |
…arse-valid # Conflicts: # docs/reference/classes/formapi.md
Fixes: #999
When performing sync validation, ensure that previous field errors are cleared if they are no longer present in the new validation result. This prevents stale validation errors from persisting in the form state.
To achieve this I have added a new prevFieldsErrorMap:
This allows us to keep track of field level errors that were added at the form level.
We then use this map to clear them out if no new errors appear for the same field.
All tests are passing. The tricky part was keeping track of what field errors were added from the form level.
Added a test covering this specific scenario within FormApi.spec.ts