Replies: 3 comments
-
Which example did you try? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Oh it didn’t link to the documentation line ? The from comportement exemple. |
Beta Was this translation helpful? Give feedback.
0 replies
-
@razvn I think the problem is that you haven't read the example the whole way though. If you paste the client side code from the example straight into a page it won't work because it is meant to be a component. To fix this you should use that code in a component as intended or adapt it by changing the code like so: <script lang="ts">
import * as Form from '$lib/components/ui/form/index.js';
import { Input } from '$lib/components/ui/input/index.js';
import { formSchema, type FormSchema } from './schema';
import { superForm } from 'sveltekit-superforms';
import { zodClient } from 'sveltekit-superforms/adapters';
+ let { data } = $props();
- export let data: SuperValidated<Infer<FormSchema>>;
+ const form = superForm(data.form, {
- const form = superForm(data, {
validators: zodClient(formSchema)
});
const { form: formData, enhance } = form;
</script>
<form method="POST" use:enhance>
<Form.Field {form} name="username">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Username</Form.Label>
<Input {...props} bind:value={$formData.username} />
{/snippet}
</Form.Control>
<Form.Description>This is your public display name.</Form.Description>
<Form.FieldErrors />
</Form.Field>
<Form.Button>Submit</Form.Button>
</form> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Change Type
Addition
Proposed Changes
I tried this exemple and got an error... with Svelte 5.
Turns out it needs:
dataType: 'json'
to work:Beta Was this translation helpful? Give feedback.
All reactions