Skip to content
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

feature(FieldAPI): Change from touched error message and error message to error map and array of errors #442

Merged
merged 7 commits into from
Sep 8, 2023

Conversation

CheRayLiu
Copy link
Contributor

@CheRayLiu CheRayLiu commented Sep 5, 2023

We'd like to change our validators to return an object and array of errors to avoid UX limitations for any app that uses TanStack Form.

Quoted from @crutchcorn. Based on the changes, an example usage in our react adapter would be:

<form.Field
  name="firstName"
  children={(field) => {
    const errArr = field.state.meta.errors // Array of errors
    const errMap = field.state.meta.errorMap; // Object of errors
    const onChangeErr = errMap?.onChange; // string | undefined | null
  }}
/>

This change includes:

  • Replacing FieldMeta.error with FieldMeta.errors and FieldMeta.errorMap
  • Replacing FieldMeta.touchedError with FieldMeta.touchedErrors
  • Updating the validation methods to accommodate those changes
  • Update documentation to reflect the changes

Resolves #431

@CheRayLiu CheRayLiu changed the title feature(FieldAPI): Change from single error message to return an error map and an array of errors feature(FieldAPI): Change from touched error message and error message to error map and array of errors Sep 5, 2023
Copy link
Member

@crutchcorn crutchcorn left a comment

Choose a reason for hiding this comment

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

Fantastic start! There's some super minor nitpicks here, but you're on an amazing track!

packages/form-core/src/FieldApi.ts Show resolved Hide resolved
packages/form-core/src/FormApi.ts Outdated Show resolved Hide resolved
packages/form-core/src/FieldApi.ts Outdated Show resolved Hide resolved
packages/form-core/src/tests/FieldApi.spec.ts Show resolved Hide resolved
…e to error map and array of errors

BREAKING CHANGE: The touched Error and error field has been removed will be replaced with touched errors array and errors map.
@CheRayLiu CheRayLiu marked this pull request as ready for review September 7, 2023 03:24
# Conflicts:
#	examples/react/simple/package.json
#	examples/vue/simple/package.json
#	pnpm-lock.yaml
@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 8, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@codecov-commenter
Copy link

Codecov Report

Patch coverage is 87.09% of modified lines.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Files Changed Coverage
packages/form-core/src/FormApi.ts 66.66%
packages/form-core/src/FieldApi.ts 88.46%
packages/form-core/src/utils.ts 100.00%

📢 Thoughts on this report? Let us know!.

@crutchcorn crutchcorn merged commit c2f9957 into TanStack:main Sep 8, 2023
5 checks passed
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.

Change from single error message to object or array of errors
3 participants