|
| 1 | +<script lang="ts"> |
| 2 | + import { page } from '$app/stores'; |
| 3 | + import { superForm, superValidateSync } from '$lib/client'; |
| 4 | + import SuperDebug from '$lib/client/SuperDebug.svelte'; |
| 5 | + import { z } from 'zod'; |
| 6 | +
|
| 7 | + const schema = z.object({ |
| 8 | + name: z.string().min(1), |
| 9 | + email: z.string().email() |
| 10 | + }); |
| 11 | +
|
| 12 | + const { form, errors, message, enhance } = superForm( |
| 13 | + superValidateSync(schema) |
| 14 | + ); |
| 15 | +</script> |
| 16 | + |
| 17 | +<div style="border: 3px solid red; padding: 10px;"> |
| 18 | + <SuperDebug data={$form} /> |
| 19 | + |
| 20 | + <h3>This is from +layout.svelte</h3> |
| 21 | + |
| 22 | + {#if $message} |
| 23 | + <div |
| 24 | + class="status" |
| 25 | + class:error={$page.status >= 400} |
| 26 | + class:success={$page.status == 200} |
| 27 | + > |
| 28 | + {$message} |
| 29 | + </div> |
| 30 | + {/if} |
| 31 | + |
| 32 | + <form method="POST" action="/tests/issue-230" use:enhance> |
| 33 | + <label> |
| 34 | + Name<br /> |
| 35 | + <input |
| 36 | + name="name" |
| 37 | + data-invalid={$errors.name} |
| 38 | + bind:value={$form.name} |
| 39 | + /> |
| 40 | + {#if $errors.name}<span class="invalid">{$errors.name}</span>{/if} |
| 41 | + </label> |
| 42 | + |
| 43 | + <label> |
| 44 | + Email<br /> |
| 45 | + <input |
| 46 | + name="email" |
| 47 | + type="email" |
| 48 | + data-invalid={$errors.email} |
| 49 | + bind:value={$form.email} |
| 50 | + /> |
| 51 | + {#if $errors.email}<span class="invalid">{$errors.email}</span>{/if} |
| 52 | + </label> |
| 53 | + |
| 54 | + <button>Submit</button> |
| 55 | + </form> |
| 56 | + |
| 57 | + <hr /> |
| 58 | + <p> |
| 59 | + <a target="_blank" href="https://superforms.vercel.app/api" |
| 60 | + >API Reference</a |
| 61 | + > |
| 62 | + </p> |
| 63 | +</div> |
| 64 | + |
| 65 | +<div style="border: 2px solid green; padding: 10px; margin-top: 10px;"> |
| 66 | + <slot /> |
| 67 | +</div> |
| 68 | + |
| 69 | +<style> |
| 70 | + .invalid { |
| 71 | + color: red; |
| 72 | + } |
| 73 | +
|
| 74 | + .status { |
| 75 | + color: white; |
| 76 | + padding: 4px; |
| 77 | + padding-left: 8px; |
| 78 | + border-radius: 2px; |
| 79 | + font-weight: 500; |
| 80 | + } |
| 81 | +
|
| 82 | + .status.success { |
| 83 | + background-color: seagreen; |
| 84 | + } |
| 85 | +
|
| 86 | + .status.error { |
| 87 | + background-color: #ff2a02; |
| 88 | + } |
| 89 | +
|
| 90 | + input { |
| 91 | + background-color: #ddd; |
| 92 | + } |
| 93 | +
|
| 94 | + a { |
| 95 | + text-decoration: underline; |
| 96 | + } |
| 97 | +
|
| 98 | + hr { |
| 99 | + margin-top: 4rem; |
| 100 | + } |
| 101 | +
|
| 102 | + form { |
| 103 | + padding-top: 1rem; |
| 104 | + padding-bottom: 1rem; |
| 105 | + } |
| 106 | +</style> |
0 commit comments