|
| 1 | +<script lang="ts"> |
| 2 | + import { page } from '$app/stores'; |
| 3 | + import { defaults, superForm } from '$lib/index.js'; |
| 4 | + import { zod } from '$lib/adapters/zod.js'; |
| 5 | + import SuperDebug from '$lib/index.js'; |
| 6 | + import { goto } from '$app/navigation'; |
| 7 | +
|
| 8 | + import { schema } from './schema.js'; |
| 9 | +
|
| 10 | + export let data; |
| 11 | +
|
| 12 | + const form = superForm(defaults(zod(schema)), { |
| 13 | + SPA: true, |
| 14 | + validators: zod(schema), |
| 15 | + async onUpdate() { |
| 16 | + // uncomment out this line to fix the redirect |
| 17 | + //cancel(); |
| 18 | + await goto('/v2/issue-360/target'); |
| 19 | + // navigating directly to the second target (no redirect) works fine |
| 20 | + // await goto('/v2/issue-360/second-target'); |
| 21 | + } |
| 22 | + }); |
| 23 | +
|
| 24 | + const { form: formStore, message, enhance } = form; |
| 25 | +</script> |
| 26 | + |
| 27 | +<SuperDebug data={$formStore} /> |
| 28 | + |
| 29 | +<h3>Superforms testing ground - Zod</h3> |
| 30 | + |
| 31 | +{#if $message} |
| 32 | + <!-- eslint-disable-next-line svelte/valid-compile --> |
| 33 | + <div class="status" class:error={$page.status >= 400} class:success={$page.status == 200}> |
| 34 | + {$message} |
| 35 | + </div> |
| 36 | +{/if} |
| 37 | + |
| 38 | +<form method="POST" use:enhance> |
| 39 | + <button>Submit</button> |
| 40 | +</form> |
| 41 | + |
| 42 | +<hr /> |
| 43 | +<p><a target="_blank" href="https://superforms.rocks/api">API Reference</a></p> |
| 44 | + |
| 45 | +<style> |
| 46 | + .invalid { |
| 47 | + color: red; |
| 48 | + } |
| 49 | +
|
| 50 | + .status { |
| 51 | + color: white; |
| 52 | + padding: 4px; |
| 53 | + padding-left: 8px; |
| 54 | + border-radius: 2px; |
| 55 | + font-weight: 500; |
| 56 | + } |
| 57 | +
|
| 58 | + .status.success { |
| 59 | + background-color: seagreen; |
| 60 | + } |
| 61 | +
|
| 62 | + .status.error { |
| 63 | + background-color: #ff2a02; |
| 64 | + } |
| 65 | +
|
| 66 | + input { |
| 67 | + background-color: #ddd; |
| 68 | + } |
| 69 | +
|
| 70 | + a { |
| 71 | + text-decoration: underline; |
| 72 | + } |
| 73 | +
|
| 74 | + hr { |
| 75 | + margin-top: 4rem; |
| 76 | + } |
| 77 | +
|
| 78 | + form { |
| 79 | + padding-top: 1rem; |
| 80 | + padding-bottom: 1rem; |
| 81 | + } |
| 82 | +</style> |
0 commit comments