-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timing issue in SPA mode displayed errors when pressing enter.
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script lang="ts"> | ||
import { superForm } from '$lib/client'; | ||
import SuperDebug from '$lib/client/SuperDebug.svelte'; | ||
export let data; | ||
let status = ''; | ||
const { form, enhance, errors } = superForm(data.form, { | ||
SPA: true, | ||
resetForm: true, | ||
validators: { | ||
title: (value) => | ||
value.trim().length >= 3 | ||
? null | ||
: 'Bitte geben Sie mindestens 3 Zeichen ein' | ||
}, | ||
onUpdate: ({ form }) => { | ||
if (form.valid) { | ||
// send data; | ||
status = 'OK'; | ||
} else { | ||
status = 'Not valid'; | ||
} | ||
} | ||
}); | ||
</script> | ||
|
||
<SuperDebug data={{ $form, $errors }} /> | ||
|
||
<h3>Superforms testing ground</h3> | ||
|
||
<p>{status}</p> | ||
|
||
<form method="POST" use:enhance> | ||
<label> | ||
Name<br /> | ||
<input | ||
class="input" | ||
type="text" | ||
bind:value={$form.title} | ||
aria-invalid={errors ? 'true' : undefined} | ||
/> | ||
</label> | ||
{#if $errors.title}<div class="invalid">{$errors.title}</div>{/if} | ||
|
||
<button>Submit</button> | ||
</form> | ||
|
||
<hr /> | ||
<p> | ||
<a target="_blank" href="https://superforms.rocks/api">API Reference</a> | ||
</p> | ||
|
||
<style> | ||
.invalid { | ||
color: red; | ||
} | ||
input { | ||
background-color: #ddd; | ||
} | ||
a { | ||
text-decoration: underline; | ||
} | ||
hr { | ||
margin-top: 4rem; | ||
} | ||
form { | ||
padding-top: 1rem; | ||
padding-bottom: 1rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { z } from 'zod'; | ||
import { superValidate } from '$lib/client'; | ||
|
||
const Schema = z.object({ | ||
title: z.string().min(3) | ||
}); | ||
|
||
export const load = async () => { | ||
const form = await superValidate(Schema); | ||
return { form }; | ||
}; |