Skip to content

Commit 8e7ca78

Browse files
authored
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
1 parent e081aca commit 8e7ca78

File tree

29 files changed

+625
-342
lines changed

29 files changed

+625
-342
lines changed

docs/config.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,8 @@
416416
"label": "react",
417417
"children": [
418418
{
419-
"label": "Balastrong's Tutorials",
420-
"to": "framework/react/community/balastrongs-tutorials"
419+
"label": "Balastrong's Tutorial",
420+
"to": "framework/react/community/balastrong-tutorial"
421421
}
422422
]
423423
}

docs/framework/angular/guides/basic-concepts.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,21 @@ export class AppComponent {
114114
}
115115
```
116116

117-
## Validation Adapters
117+
## Validation with Schema Libraries
118118

119-
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/).
119+
In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification.
120+
121+
You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator.
122+
123+
Supported libraries include:
124+
125+
- [Zod](https://zod.dev/)
126+
- [Valibot](https://valibot.dev/)
127+
- [ArkType](https://arktype.io/)
120128

121129
Example:
122130

123131
```angular-ts
124-
import { zodValidator } from '@tanstack/zod-form-adapter'
125132
import { z } from 'zod'
126133
127134
@Component({
@@ -132,7 +139,6 @@ import { z } from 'zod'
132139
<ng-container
133140
[tanstackField]="form"
134141
name="firstName"
135-
[validatorAdapter]="zodValidator()"
136142
[validators]="{
137143
onChange: z.string().min(3, 'First name must be at least 3 characters'),
138144
onChangeAsyncDebounceMs: 500,
@@ -166,7 +172,6 @@ export class AppComponent {
166172
})
167173
168174
z = z
169-
zodValidator = zodValidator
170175
}
171176
```
172177

docs/framework/react/community/balastrongs-tutorials.md renamed to docs/framework/react/community/balastrongs-tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
id: balastrongs-tutorials
3-
title: Balastrong's Tutorials
2+
id: balastrong-tutorial
3+
title: Balastrong's Tutorial
44
---
55

66
TanStack Form maintainer [Balastrong](https://bsky.app/profile/leonardomontini.dev) has created a series of video tutorials showcasing the most relevant features of the library. You'll find step by step guides that give you some extra insights into what you can build with TanStack Form, plus some nice tips and tricks.

docs/framework/react/guides/basic-concepts.md

+32-23
Original file line numberDiff line numberDiff line change
@@ -144,34 +144,43 @@ Example:
144144
/>
145145
```
146146

147-
## Validation Adapters
147+
## Validation with Schema Libraries
148148

149-
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/).
149+
In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification.
150150

151-
Example:
151+
You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator.
152+
153+
Supported libraries include:
154+
155+
- [Zod](https://zod.dev/)
156+
- [Valibot](https://valibot.dev/)
157+
- [ArkType](https://arktype.io/)
152158

153159
```tsx
154-
import { zodValidator } from '@tanstack/zod-form-adapter'
155-
import { z } from 'zod'
160+
const userSchema = z.object({
161+
age: z.number().gte(13, 'You must be 13 to make an account'),
162+
})
156163

157-
// ...
158-
<form.Field
159-
name="firstName"
160-
validatorAdapter={zodValidator()}
161-
validators={{
162-
onChange: z.string().min(3, 'First name must be at least 3 characters'),
163-
onChangeAsyncDebounceMs: 500,
164-
onChangeAsync: z.string().refine(
165-
async (value) => {
166-
await new Promise((resolve) => setTimeout(resolve, 1000))
167-
return !value.includes('error')
168-
},
169-
{
170-
message: "No 'error' allowed in first name",
171-
},
172-
),
173-
}}
174-
/>
164+
function App() {
165+
const form = useForm({
166+
defaultValues: {
167+
age: 0,
168+
},
169+
validators: {
170+
onChange: userSchema,
171+
},
172+
})
173+
return (
174+
<div>
175+
<form.Field
176+
name="age"
177+
children={(field) => {
178+
return <>{/* ... */}</>
179+
}}
180+
/>
181+
</div>
182+
)
183+
}
175184
```
176185

177186
## Reactivity

docs/framework/solid/guides/basic-concepts.md

+9-5
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,24 @@ Example:
139139
/>
140140
```
141141

142-
## Validation Adapters
142+
## Validation with Schema Libraries
143143

144-
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/).
144+
In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification.
145145

146-
Example:
146+
You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator.
147+
148+
Supported libraries include:
149+
150+
- [Zod](https://zod.dev/)
151+
- [Valibot](https://valibot.dev/)
152+
- [ArkType](https://arktype.io/)
147153

148154
```tsx
149-
import { zodValidator } from '@tanstack/zod-form-adapter'
150155
import { z } from 'zod'
151156

152157
// ...
153158
<form.Field
154159
name="firstName"
155-
validatorAdapter={zodValidator()}
156160
validators={{
157161
onChange: z.string().min(3, 'First name must be at least 3 characters'),
158162
onChangeAsyncDebounceMs: 500,

docs/framework/vue/guides/basic-concepts.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -146,22 +146,25 @@ Example:
146146
</template>
147147
```
148148

149-
## Validation Adapters
149+
## Validation with Schema Libraries
150150

151-
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/).
151+
In addition to hand-rolled validation options, we also support the [Standard Schema](https://github.com/standard-schema/standard-schema) specification.
152152

153-
Example:
153+
You can define a schema using any of the libraries implementing the specification and pass it to a form or field validator.
154+
155+
Supported libraries include:
156+
157+
- [Zod](https://zod.dev/)
158+
- [Valibot](https://valibot.dev/)
159+
- [ArkType](https://arktype.io/)
154160

155161
```vue
156162
<script setup lang="ts">
157163
import { useForm } from '@tanstack/vue-form'
158-
import { zodValidator } from '@tanstack/zod-form-adapter'
159164
import { z } from 'zod'
160165
161166
const form = useForm({
162167
// ...
163-
// Add a validator to support Zod usage in Form and Field
164-
validatorAdapter: zodValidator(),
165168
})
166169
167170
const onChangeFirstName = z.string().refine(

0 commit comments

Comments
 (0)