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

docs: include key and defaultValue in the integration examples #642

Merged
merged 2 commits into from
May 20, 2024
Merged
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
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
singleQuote: true
useTabs: true
trailingComma: all
overrides:
- files:
- '*.md'
options:
useTabs: false
tabWidth: 2
28 changes: 22 additions & 6 deletions docs/integration/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const loginSchema = z.object({
});

// action.ts
'use server';
('use server');

import { redirect } from 'next/navigation';
import { parseWithZod } from '@conform-to/zod';
Expand All @@ -32,7 +32,7 @@ export async function login(prevState: unknown, formData: FormData) {
}

// form.tsx
'use client';
('use client');

import { useForm } from '@conform-to/react';
import { parseWithZod } from '@conform-to/zod';
Expand All @@ -53,27 +53,43 @@ export function LoginForm() {

// Validate the form on blur event triggered
shouldValidate: 'onBlur',
shouldRevalidate: 'onInput',
});

return (
<form id={form.id} onSubmit={form.onSubmit} action={action} noValidate>
<div>
<label>Email</label>
<input type="email" name={fields.email.name} />
<input
type="email"
key={fields.email.key}
name={fields.email.name}
defaultValue={fields.email.initialValue}
/>
<div>{fields.email.errors}</div>
</div>
<div>
<label>Password</label>
<input type="password" name={fields.password.name} />
<input
type="password"
key={fields.password.key}
name={fields.password.name}
defaultValue={fields.password.initialValue}
/>
<div>{fields.password.errors}</div>
</div>
<label>
<div>
<span>Remember me</span>
<input type="checkbox" name={fields.remember.name} />
<input
type="checkbox"
key={fields.remember.key}
name={fields.remember.name}
defaultChecked={fields.remember.initialValue === 'on'}
/>
</div>
</label>
<Button>Login</Button>
<button>Login</button>
</form>
);
}
Expand Down
24 changes: 20 additions & 4 deletions docs/integration/remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,40 @@ export default function Login() {

// Validate the form on blur event triggered
shouldValidate: 'onBlur',
shouldRevalidate: 'onInput',
});

return (
<Form method="post" id={form.id} onSubmit={form.onSubmit}>
<Form method="post" id={form.id} onSubmit={form.onSubmit} noValidate>
<div>
<label>Email</label>
<input type="email" name={fields.email.name} />
<input
type="email"
key={fields.email.key}
name={fields.email.name}
defaultValue={fields.email.initialValue}
/>
<div>{fields.email.errors}</div>
</div>
<div>
<label>Password</label>
<input type="password" name={fields.password.name} />
<input
type="password"
key={fields.password.key}
name={fields.password.name}
defaultValue={fields.password.initialValue}
/>
<div>{fields.password.errors}</div>
</div>
<label>
<div>
<span>Remember me</span>
<input type="checkbox" name={fields.remember.name} />
<input
type="checkbox"
key={fields.remember.key}
name={fields.remember.name}
defaultChecked={fields.remember.initialValue === 'on'}
/>
</div>
</label>
<hr />
Expand Down
24 changes: 20 additions & 4 deletions docs/ja/integration/nextjs.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,43 @@ export function LoginForm() {

// blurイベント発生時にフォームを検証する
shouldValidate: 'onBlur',
shouldRevalidate: 'onInput',
});

return (
<form id={form.id} onSubmit={form.onSubmit} action={action} noValidate>
<div>
<label>Email</label>
<input type="email" name={fields.email.name} />
<input
type="email"
key={fields.email.key}
name={fields.email.name}
defaultValue={fields.email.initialValue}
/>
<div>{fields.email.errors}</div>
</div>
<div>
<label>Password</label>
<input type="password" name={fields.password.name} />
<input
type="password"
key={fields.password.key}
name={fields.password.name}
defaultValue={fields.password.initialValue}
/>
<div>{fields.password.errors}</div>
</div>
<label>
<div>
<span>Remember me</span>
<input type="checkbox" name={fields.remember.name} />
<input
type="checkbox"
key={fields.remember.key}
name={fields.remember.name}
defaultChecked={fields.remember.initialValue === 'on'}
/>
</div>
</label>
<Button>Login</Button>
<button>Login</button>
</form>
);
}
Expand Down
24 changes: 20 additions & 4 deletions docs/ja/integration/remix.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,40 @@ export default function Login() {

// blurイベント発生時にフォームを検証する
shouldValidate: 'onBlur',
shouldRevalidate: 'onInput',
});

return (
<Form method="post" id={form.id} onSubmit={form.onSubmit}>
<Form method="post" id={form.id} onSubmit={form.onSubmit} noValidate>
<div>
<label>Email</label>
<input type="email" name={fields.email.name} />
<input
type="email"
key={fields.email.key}
name={fields.email.name}
defaultValue={fields.email.initialValue}
/>
<div>{fields.email.errors}</div>
</div>
<div>
<label>Password</label>
<input type="password" name={fields.password.name} />
<input
type="password"
key={fields.password.key}
name={fields.password.name}
defaultValue={fields.password.initialValue}
/>
<div>{fields.password.errors}</div>
</div>
<label>
<div>
<span>Remember me</span>
<input type="checkbox" name={fields.remember.name} />
<input
type="checkbox"
key={fields.remember.key}
name={fields.remember.name}
defaultChecked={fields.remember.initialValue === 'on'}
/>
</div>
</label>
<hr />
Expand Down
Loading