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

fix(docs): update valibot snippet #6569

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
24 changes: 13 additions & 11 deletions packages/docs/src/routes/demo/integration/modular-forms/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import { $, component$, type QRL } from '@builder.io/qwik';
import { routeLoader$ } from '@builder.io/qwik-city';
import type { InitialValues, SubmitHandler } from '@modular-forms/qwik';
import { formAction$, useForm, valiForm$ } from '@modular-forms/qwik';
import { email, type Input, minLength, object, string } from 'valibot';
import * as v from 'valibot';

const LoginSchema = object({
email: string([
minLength(1, 'Please enter your email.'),
email('The email address is badly formatted.'),
]),
password: string([
minLength(1, 'Please enter your password.'),
minLength(8, 'Your password must have 8 characters or more.'),
]),
const LoginSchema = v.object({
email: v.pipe(
v.string(),
v.minLength(1, 'Please enter your email.'),
v.email('The email address is badly formatted.'),
),
password: v.pipe(
v.string(),
v.minLength(1, 'Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.'),
),
});

type LoginForm = Input<typeof LoginSchema>;
type LoginForm = v.InferInput<typeof LoginSchema>;

export const useFormLoader = routeLoader$<InitialValues<LoginForm>>(() => ({
email: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,22 @@ type LoginForm = {
Since Modular Forms supports [Valibot](https://valibot.dev/) and [Zod](https://zod.dev/) for input validation, you can optionally derive the type definition from a schema.

```ts
import { email, type Input, minLength, object, string } from 'valibot';

const LoginSchema = object({
email: string([
minLength(1, 'Please enter your email.'),
email('The email address is badly formatted.'),
]),
password: string([
minLength(1, 'Please enter your password.'),
minLength(8, 'Your password must have 8 characters or more.'),
]),
import * as v from 'valibot';

const LoginSchema = v.object({
email: v.pipe(
v.string(),
v.minLength(1, 'Please enter your email.'),
v.email('he email address is badly formatted.'),
),
password: v.pipe(
v.string(),
v.minLength(1, 'Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.'),
),
});

type LoginForm = Input<typeof LoginSchema>;
type LoginForm = v.InferInput<typeof LoginSchema>;
```

If you're wondering why this guide favors Valibot over Zod, I recommend reading this [announcement post](https://www.builder.io/blog/introducing-valibot).
Expand Down Expand Up @@ -183,20 +185,22 @@ import { $, component$, type QRL } from '@builder.io/qwik';
import { routeLoader$ } from '@builder.io/qwik-city';
import type { InitialValues, SubmitHandler } from '@modular-forms/qwik';
import { formAction$, useForm, valiForm$ } from '@modular-forms/qwik';
import { email, type Input, minLength, object, string } from 'valibot';

const LoginSchema = object({
email: string([
minLength(1, 'Please enter your email.'),
email('The email address is badly formatted.'),
]),
password: string([
minLength(1, 'Please enter your password.'),
minLength(8, 'Your password must have 8 characters or more.'),
]),
import * as v from 'valibot';

const LoginSchema = v.object({
email: v.pipe(
v.string(),
v.minLength(1, 'Please enter your email.'),
v.email('The email address is badly formatted.'),
),
password: v.pipe(
v.string(),
v.minLength(1, 'Please enter your password.'),
v.minLength(8, 'Your password must have 8 characters or more.'),
),
});

type LoginForm = Input<typeof LoginSchema>;
type LoginForm = v.InferInput<typeof LoginSchema>;

export const useFormLoader = routeLoader$<InitialValues<LoginForm>>(() => ({
email: '',
Expand Down
Loading