Skip to content

Commit e09a218

Browse files
committed
Proxy in proxy test.
1 parent a2401c9 commit e09a218

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { message, superValidate } from '$lib/server';
2+
import { schema } from './schema';
3+
import { fail } from '@sveltejs/kit';
4+
5+
export const load = async () => {
6+
const form = await superValidate(schema);
7+
return { form };
8+
};
9+
10+
export const actions = {
11+
default: async ({ request }) => {
12+
const formData = await request.formData();
13+
console.log(formData);
14+
15+
const form = await superValidate(formData, schema);
16+
console.log('POST', form);
17+
18+
if (!form.valid) return fail(400, { form });
19+
20+
return message(form, 'Posted OK!');
21+
}
22+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script lang="ts">
2+
import { dateProxy, formFieldProxy, superForm } from '$lib/client';
3+
import type { PageData } from './$types';
4+
5+
export let data: PageData;
6+
7+
const theForm = superForm(data.form);
8+
const { errors } = formFieldProxy(theForm, 'date');
9+
const date = dateProxy(theForm.form, 'date', { format: 'date' });
10+
</script>
11+
12+
<form method="POST" use:theForm.enhance>
13+
<label>
14+
Date: <input name="date" type="date" bind:value={$date} />
15+
{#if $errors}<span class="invalid">{$errors}</span>{/if}
16+
</label>
17+
<div>
18+
<button>Submit</button>
19+
</div>
20+
</form>
21+
22+
<style lang="scss">
23+
form {
24+
margin: 2rem 0;
25+
26+
input {
27+
background-color: #dedede;
28+
}
29+
30+
.invalid {
31+
color: crimson;
32+
}
33+
}
34+
</style>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { z } from 'zod';
2+
3+
export const schema = z.object({
4+
date: z.date()
5+
});

0 commit comments

Comments
 (0)