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

chore: update tutorial regarding empty string default value support #843

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions docs/ja/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ npm install @conform-to/react @conform-to/zod --save
import { z } from 'zod';

const schema = z.object({
// zodが必要なチェックを適切に実行するためには、前処理ステップが必要です。
// 空の入力の値は通常、空の文字列であるためです。
email: z.preprocess(
(value) => (value === '' ? undefined : value),
z.string({ required_error: 'Email is required' }).email('Email is invalid'),
),
message: z.preprocess(
(value) => (value === '' ? undefined : value),
z
.string({ required_error: 'Message is required' })
.min(10, 'Message is too short')
.max(100, 'Message is too long'),
),
email: z
.string({ required_error: 'Email is required' })
.email('Email is invalid'),
message: z
.string({ required_error: 'Message is required' })
.min(10, 'Message is too short')
.max(100, 'Message is too long'),
});
```

Expand Down
20 changes: 7 additions & 13 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@ First, let's define the schema. Here is a zod schema that we will use to validat
import { z } from 'zod';

const schema = z.object({
// The preprocess step is required for zod to perform the required check properly
// as the value of an empty input is usually an empty string
email: z.preprocess(
(value) => (value === '' ? undefined : value),
z.string({ required_error: 'Email is required' }).email('Email is invalid'),
),
message: z.preprocess(
(value) => (value === '' ? undefined : value),
z
.string({ required_error: 'Message is required' })
.min(10, 'Message is too short')
.max(100, 'Message is too long'),
),
email: z
.string({ required_error: 'Email is required' })
.email('Email is invalid'),
message: z
.string({ required_error: 'Message is required' })
.min(10, 'Message is too short')
.max(100, 'Message is too long'),
});
```

Expand Down
Loading