Skip to content

Commit 9012284

Browse files
committed
Valibot requires 1.0.0-beta.3
Fixes #503 Fixes #505
1 parent ba7de2a commit 9012284

File tree

6 files changed

+123
-10
lines changed

6 files changed

+123
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Valibot updated to require `1.0.0-beta.3` (hoping for a stable release soon).
13+
1014
### Added
1115

1216
- Support for Vine 2.0.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"joi": "^17.13.1",
115115
"superstruct": "^2.0.2",
116116
"svelte": "3.x || 4.x || >=5.0.0-next.51",
117-
"valibot": ">=0.33.0 <1",
117+
"valibot": ">=1.0.0-beta.3",
118118
"yup": "^1.4.0",
119119
"zod": "^3.23.8"
120120
},
@@ -172,7 +172,7 @@
172172
"joi": "^17.13.3",
173173
"json-schema-to-ts": "^3.1.1",
174174
"superstruct": "^2.0.2",
175-
"valibot": "^0.41.0",
175+
"valibot": "^1.0.0-beta.3",
176176
"yup": "^1.4.0",
177177
"zod": "^3.23.8",
178178
"zod-to-json-schema": "^3.23.3"

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { superValidate, message } from '$lib/index.js';
2+
import { valibot } from '$lib/adapters/valibot.js';
3+
import { fail } from '@sveltejs/kit';
4+
import { schema } from './schema.js';
5+
6+
export const load = async () => {
7+
const form = await superValidate(valibot(schema));
8+
return { form };
9+
};
10+
11+
export const actions = {
12+
default: async ({ request }) => {
13+
const form = await superValidate(request, valibot(schema));
14+
console.log(form);
15+
16+
if (!form.valid) return fail(400, { form });
17+
18+
return message(form, 'Form posted successfully!');
19+
}
20+
};
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<script lang="ts">
2+
import { page } from '$app/stores';
3+
import { superForm } from '$lib/index.js';
4+
import SuperDebug from '$lib/index.js';
5+
6+
export let data;
7+
8+
const { form, errors, message, enhance } = superForm(data.form);
9+
</script>
10+
11+
<SuperDebug data={$form} />
12+
13+
<h3>Nullable Valibot schema</h3>
14+
15+
{#if $message}
16+
<!-- eslint-disable-next-line svelte/valid-compile -->
17+
<div class="status" class:error={$page.status >= 400} class:success={$page.status == 200}>
18+
{$message}
19+
</div>
20+
{/if}
21+
22+
<form method="POST" use:enhance>
23+
<label>
24+
Name<br />
25+
<input name="name" aria-invalid={$errors.name ? 'true' : undefined} bind:value={$form.name} />
26+
{#if $errors.name}<span class="invalid">{$errors.name}</span>{/if}
27+
</label>
28+
29+
<label>
30+
Email<br />
31+
<input
32+
name="email"
33+
type="email"
34+
aria-invalid={$errors.email ? 'true' : undefined}
35+
bind:value={$form.email}
36+
/>
37+
{#if $errors.email}<span class="invalid">{$errors.email}</span>{/if}
38+
</label>
39+
40+
<button>Submit</button>
41+
</form>
42+
43+
<hr />
44+
<p><a target="_blank" href="https://superforms.rocks/api">API Reference</a></p>
45+
46+
<style>
47+
.invalid {
48+
color: red;
49+
}
50+
51+
.status {
52+
color: white;
53+
padding: 4px;
54+
padding-left: 8px;
55+
border-radius: 2px;
56+
font-weight: 500;
57+
}
58+
59+
.status.success {
60+
background-color: seagreen;
61+
}
62+
63+
.status.error {
64+
background-color: #ff2a02;
65+
}
66+
67+
input {
68+
background-color: #ddd;
69+
}
70+
71+
a {
72+
text-decoration: underline;
73+
}
74+
75+
hr {
76+
margin-top: 4rem;
77+
}
78+
79+
form {
80+
padding-top: 1rem;
81+
padding-bottom: 1rem;
82+
}
83+
</style>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { object, string, minLength, email, pipe } from 'valibot';
2+
3+
export const schema = object({
4+
name: pipe(string(), minLength(2)),
5+
email: pipe(string(), email())
6+
});

0 commit comments

Comments
 (0)