|
| 1 | +<script lang="ts"> |
| 2 | + import { zod, zodClient } from '$lib/adapters/zod.js'; |
| 3 | + import { defaults, superForm } from '$lib/client/index.js'; |
| 4 | + import SuperDebug from '$lib/client/SuperDebug.svelte'; |
| 5 | + import { schema } from './schema.js'; |
| 6 | + import { page } from '$app/stores'; |
| 7 | + //import { zod } from '$lib/adapters/zod.js' |
| 8 | + //import { schema } from './schema.js'; |
| 9 | +
|
| 10 | + export let data; |
| 11 | +
|
| 12 | + const { form, errors, tainted, message, enhance, formId } = superForm(data.form, { |
| 13 | + validators: zodClient(schema), |
| 14 | + taintedMessage: false, |
| 15 | + resetForm: true |
| 16 | + }); |
| 17 | +
|
| 18 | + const { |
| 19 | + form: formData, |
| 20 | + errors: errors2, |
| 21 | + formId: formId2, |
| 22 | + enhance: enhance2, |
| 23 | + posted |
| 24 | + } = superForm(defaults(zod(schema)), { |
| 25 | + id: 'abc', |
| 26 | + taintedMessage: false, |
| 27 | + invalidateAll: false, |
| 28 | + resetForm: true, |
| 29 | + validators: zodClient(schema) |
| 30 | + }); |
| 31 | +
|
| 32 | + // eslint-disable-next-line svelte/valid-compile |
| 33 | + $page; |
| 34 | +</script> |
| 35 | + |
| 36 | +<SuperDebug data={{ $form, $errors, $tainted }} /> |
| 37 | + |
| 38 | +{JSON.stringify($page.form)} |
| 39 | + |
| 40 | +{#if $message}<h4>{$message}</h4>{/if} |
| 41 | + |
| 42 | +<form method="POST" use:enhance> |
| 43 | + <div>FORMID:{$formId}:</div> |
| 44 | + <div>POSTED:{$posted}:</div> |
| 45 | + <label> |
| 46 | + Name: <input |
| 47 | + name="name" |
| 48 | + bind:value={$form.name} |
| 49 | + aria-invalid={$errors.name ? 'true' : undefined} |
| 50 | + /> |
| 51 | + {#if $errors.name}<span class="invalid">{$errors.name}</span>{/if} |
| 52 | + </label> |
| 53 | + <label> |
| 54 | + Email: <input |
| 55 | + name="email" |
| 56 | + bind:value={$form.email} |
| 57 | + aria-invalid={$errors.email ? 'true' : undefined} |
| 58 | + /> |
| 59 | + {#if $errors.email}<span class="invalid">{$errors.email}</span>{/if} |
| 60 | + </label> |
| 61 | + <div> |
| 62 | + <button>Submit</button> |
| 63 | + </div> |
| 64 | +</form> |
| 65 | + |
| 66 | +<form method="POST" use:enhance2> |
| 67 | + <div>FORMID:{$formId2}:</div> |
| 68 | + <div>POSTED:{$posted}:</div> |
| 69 | + <label> |
| 70 | + Name2: <input name="name" bind:value={$formData.name} /> |
| 71 | + {#if $errors2.name}<span class="invalid">{$errors2.name}</span>{/if} |
| 72 | + </label> |
| 73 | + <label> |
| 74 | + Email: <input |
| 75 | + name="email" |
| 76 | + bind:value={$formData.email} |
| 77 | + aria-invalid={$errors2.email ? 'true' : undefined} |
| 78 | + /> |
| 79 | + {#if $errors2.email}<span class="invalid">{$errors2.email}</span>{/if} |
| 80 | + </label> |
| 81 | + <div> |
| 82 | + <button>Submit</button> |
| 83 | + </div> |
| 84 | +</form> |
| 85 | + |
| 86 | +<style lang="scss"> |
| 87 | + form { |
| 88 | + margin: 2rem 0; |
| 89 | +
|
| 90 | + input { |
| 91 | + background-color: #dedede; |
| 92 | + } |
| 93 | +
|
| 94 | + .invalid { |
| 95 | + color: crimson; |
| 96 | + } |
| 97 | + } |
| 98 | +</style> |
0 commit comments