From 8e7ca78861853de0dca25f26dead7309f0307b7f Mon Sep 17 00:00:00 2001 From: Leonardo Montini Date: Wed, 11 Dec 2024 21:29:49 +0100 Subject: [PATCH] fix: allow standard schema validator on field validators without explicit adapter (#1064) * fix: allow standard schema validator on fields without adapter * doc: mention standard schema in basic-concepts --- docs/config.json | 4 +- .../angular/guides/basic-concepts.md | 15 +- ...s-tutorials.md => balastrongs-tutorial.md} | 4 +- docs/framework/react/guides/basic-concepts.md | 55 +- docs/framework/solid/guides/basic-concepts.md | 14 +- docs/framework/vue/guides/basic-concepts.md | 15 +- docs/reference/classes/fieldapi.md | 48 +- .../functions/isstandardschemavalidator.md | 4 +- .../functions/standardschemavalidator.md | 4 +- docs/reference/interfaces/fieldapioptions.md | 18 +- docs/reference/interfaces/fieldlisteners.md | 8 +- docs/reference/interfaces/fieldoptions.md | 16 +- docs/reference/interfaces/fieldvalidators.md | 22 +- docs/reference/type-aliases/fieldmeta.md | 2 +- docs/reference/type-aliases/fieldstate.md | 2 +- .../angular/valibot/src/app/app.component.ts | 2 +- examples/angular/zod/src/app/app.component.ts | 2 +- examples/react/valibot/src/index.tsx | 2 +- examples/react/zod/src/index.tsx | 2 +- examples/solid/valibot/src/index.tsx | 2 +- examples/solid/zod/src/index.tsx | 2 +- examples/vue/valibot/src/App.vue | 2 +- examples/vue/zod/src/App.vue | 2 +- packages/form-core/package.json | 2 +- packages/form-core/src/FieldApi.ts | 33 +- packages/form-core/src/FormApi.ts | 6 +- .../form-core/src/standardSchemaValidator.ts | 22 +- .../tests/standardSchemaValidator.spec.ts | 35 +- pnpm-lock.yaml | 622 ++++++++++++------ 29 files changed, 625 insertions(+), 342 deletions(-) rename docs/framework/react/community/{balastrongs-tutorials.md => balastrongs-tutorial.md} (97%) diff --git a/docs/config.json b/docs/config.json index 714371ee5..fcfef6fd5 100644 --- a/docs/config.json +++ b/docs/config.json @@ -416,8 +416,8 @@ "label": "react", "children": [ { - "label": "Balastrong's Tutorials", - "to": "framework/react/community/balastrongs-tutorials" + "label": "Balastrong's Tutorial", + "to": "framework/react/community/balastrong-tutorial" } ] } diff --git a/docs/framework/angular/guides/basic-concepts.md b/docs/framework/angular/guides/basic-concepts.md index 3f8860260..0fa5d6bf0 100644 --- a/docs/framework/angular/guides/basic-concepts.md +++ b/docs/framework/angular/guides/basic-concepts.md @@ -114,14 +114,21 @@ export class AppComponent { } ``` -## Validation Adapters +## Validation with Schema Libraries -In addition to hand-rolled validation options, we also provide adapters like `@tanstack/zod-form-adapter`, `@tanstack/yup-form-adapter`, and `@tanstack/valibot-form-adapter` to enable usage with common schema validation tools like [Zod](https://zod.dev/), [Yup](https://github.com/jquense/yup), and [Valibot](https://valibot.dev/). +In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification. + +You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator. + +Supported libraries include: + +- [Zod](https://zod.dev/) +- [Valibot](https://valibot.dev/) +- [ArkType](https://arktype.io/) Example: ```angular-ts -import { zodValidator } from '@tanstack/zod-form-adapter' import { z } from 'zod' @Component({ @@ -132,7 +139,6 @@ import { z } from 'zod' { - await new Promise((resolve) => setTimeout(resolve, 1000)) - return !value.includes('error') - }, - { - message: "No 'error' allowed in first name", - }, - ), - }} -/> +function App() { + const form = useForm({ + defaultValues: { + age: 0, + }, + validators: { + onChange: userSchema, + }, + }) + return ( +
+ { + return <>{/* ... */} + }} + /> +
+ ) +} ``` ## Reactivity diff --git a/docs/framework/solid/guides/basic-concepts.md b/docs/framework/solid/guides/basic-concepts.md index eb3cf2a13..766b92545 100644 --- a/docs/framework/solid/guides/basic-concepts.md +++ b/docs/framework/solid/guides/basic-concepts.md @@ -139,20 +139,24 @@ Example: /> ``` -## Validation Adapters +## Validation with Schema Libraries -In addition to hand-rolled validation options, we also provide adapters like `@tanstack/zod-form-adapter`, `@tanstack/yup-form-adapter`, and `@tanstack/valibot-form-adapter` to enable usage with common schema validation tools like [Zod](https://zod.dev/), [Yup](https://github.com/jquense/yup), and [Valibot](https://valibot.dev/). +In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification. -Example: +You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator. + +Supported libraries include: + +- [Zod](https://zod.dev/) +- [Valibot](https://valibot.dev/) +- [ArkType](https://arktype.io/) ```tsx -import { zodValidator } from '@tanstack/zod-form-adapter' import { z } from 'zod' // ... ``` -## Validation Adapters +## Validation with Schema Libraries -In addition to hand-rolled validation options, we also provide adapters like `@tanstack/zod-form-adapter`, `@tanstack/yup-form-adapter`, and `@tanstack/valibot-form-adapter` to enable usage with common schema validation tools like [Zod](https://zod.dev/), [Yup](https://github.com/jquense/yup), and [Valibot](https://valibot.dev/). +In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification. -Example: +You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator. + +Supported libraries include: + +- [Zod](https://zod.dev/) +- [Valibot](https://valibot.dev/) +- [ArkType](https://arktype.io/) ```vue