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

[WIP] [FEAT] Allow returning anything in a validator, not just a string #1104

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

crutchcorn
Copy link
Member

@crutchcorn crutchcorn commented Jan 9, 2025

This PR allows you to return non-string values from validators:

<form.Field name="password" validators={{onChange: () => ({hasUppercase: false, hasLowercase: true}) }} />

In addition, it also enforces type safety on the returned value on both errorMap and the errors array:

const form = new FormApi({
  defaultValues: {
    name: 'test',
  },
} as const)

const field = new FieldApi({
  form,
  name: 'name',
  validators: {
    onChange: () => {
      return 123 as const
    },
  },
})

assertType<123 | undefined>(field.state.meta.errorMap.onChange)

assertType<Array<123 | undefined>>(field.state.meta.errors)

Start Adapter Fixes

Along the way, I wanted to fix the Start adapter, so we're doing so in this PR. Fixes: #1023

Vue typings

This PR also fixes the issues with Vue SFC format and marks Vue 3.4 as the new minimum supported version

TODO

Copy link

nx-cloud bot commented Jan 9, 2025

View your CI Pipeline Execution ↗ for commit 69c1897.

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

☁️ Nx Cloud last updated this comment at 2025-01-11 18:03:51 UTC

@crutchcorn crutchcorn changed the title [FIX] Allow returning anything in a validator, not just a string [WIP] [FIX] Allow returning anything in a validator, not just a string Jan 9, 2025
@crutchcorn crutchcorn marked this pull request as draft January 9, 2025 08:56
Copy link

pkg-pr-new bot commented Jan 9, 2025

Open in Stackblitz

More templates

@tanstack/angular-form

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

@tanstack/form-core

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

@tanstack/react-form

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

@tanstack/solid-form

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

@tanstack/valibot-form-adapter

npm i https://pkg.pr.new/@tanstack/valibot-form-adapter@1104

@tanstack/lit-form

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

@tanstack/vue-form

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

@tanstack/yup-form-adapter

npm i https://pkg.pr.new/@tanstack/yup-form-adapter@1104

@tanstack/zod-form-adapter

npm i https://pkg.pr.new/@tanstack/zod-form-adapter@1104

commit: 69c1897

@crutchcorn crutchcorn changed the title [WIP] [FIX] Allow returning anything in a validator, not just a string [WIP] [FEAT] Allow returning anything in a validator, not just a string Jan 10, 2025
@crutchcorn crutchcorn force-pushed the return-anything-not-just-string branch from 20e5b68 to c9ea6cf Compare January 11, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update TanStack Start adapter
1 participant