` props, `ref` for element access, and `child` for custom rendering.
```APIDOC
Description Component Props:
- ref:
type: HTMLElement | null
description: A reference to the underlying HTML element rendered by the `Description` component.
example:
- child:
type: Snippet
description: If provided, the `Description` component will not render an HTML element and will instead expect you to spread the snippet's `props` onto an element of your choosing. See the `child` snippet documentation for more information.
- ...rest:
type: HTMLAttributes
description: Any additional props provided to the `Description` component will be spread onto the underlying HTML element.
```
--------------------------------
### Initialize SvelteKit SuperForm for Dynamic Fields
Source: https://www.formsnap.dev/docs/recipes/dynamic-fields
This snippet initializes a SvelteKit SuperForm instance, binding it to the form data from the load function and applying Zod client-side validation. It sets up the basic HTML form structure for submission.
```Svelte
```
--------------------------------
### Import Formsnap Components for Form Building
Source: https://www.formsnap.dev/docs/recipes/multiple-select
This snippet demonstrates importing essential Formsnap components: `Field`, `Control`, `Label`, and `FieldErrors`. These components are crucial for structuring and displaying form elements and their associated validation messages within a SvelteKit SuperForm. Dependencies: `formsnap`.
```Svelte
```
--------------------------------
### Configure SvelteKit Load Function and Actions for Form Submission
Source: https://www.formsnap.dev/docs/recipes/checkbox-groups
This snippet sets up the `load` function and `actions` in a SvelteKit `+page.server.ts` file to handle form data. It uses `sveltekit-superforms` with the `zod` adapter to validate incoming form data against a shared schema, returning a 400 error with the form object if validation fails. This ensures server-side data integrity.
```typescript
import { superValidate } from "sveltekit-superforms";
import type { Actions, PageServerLoad } from "./$types";
import { schema } from "./+page.svelte";
import { zod } from "sveltekit-superforms/adapters";
import { fail } from "@sveltejs/kit";
export const load: PageServerLoad = async () => {
return {
form: await superValidate(zod(schema)),
};
};
export const actions: Actions = {
default: async (event) => {
const form = await superValidate(event, zod(schema));
if (!form.valid) {
return fail(400, { form });
}
return { form };
},
};
```
--------------------------------
### Import Formsnap Components for Dynamic Fields
Source: https://www.formsnap.dev/docs/recipes/dynamic-fields
This snippet extends the Svelte component by importing necessary Formsnap components like Fieldset, Legend, ElementField, Control, Label, FieldErrors, and Description. These components are essential for building the dynamic URL form structure.
```Svelte
```
--------------------------------
### Svelte: Import Formsnap Components and Enhance Form
Source: https://www.formsnap.dev/docs/recipes/checkbox-groups
This snippet demonstrates how to import necessary components from sveltekit-superforms and formsnap to initialize a SuperForm. It sets up a form element with the enhance action for client-side validation, binding the form data to a SuperForm instance.
```Svelte
```
--------------------------------
### useFormField Hook API Reference
Source: https://www.formsnap.dev/docs/composition/use-form-field
This section provides a detailed API reference for the `useFormField` hook, outlining its configurable properties and the structure of the object it returns. It covers the `errorsId` and `descriptionId` props, and the `UseFormFieldReturn` type with its various state properties.
```APIDOC
Props:
errorsId:
type: () => string | undefined | null
description: Optionally provide a getter function that returns a custom ID to override the errors container ID.
descriptionId:
type: () => string | undefined | null
description: Optionally provide a getter function that returns a custom ID to override the description container ID.
Return Type:
UseFormFieldReturn, U extends FormPath>:
form: SuperForm (The original form store passed to the `*Field` component.)
readonly errorsId: string (Reactive state containing the ID of the field errors container for the field.)
readonly descriptionId: string (Reactive state containing the ID of the description element for the field.)
readonly name: U (Reactive state containing the name of the field.)
readonly errors: string[] (Reactive state containing the current validations errors for the field.)
readonly constraints: Record (Reactive state containing the constraints (if any) for the field.)
readonly tainted: boolean (Reactive state containing the tainted state of the field.)
Warning:
The `useFormField` function returns getters for the various reactive states. You should not destructure the object returned by `useFormField` and instead use the getters directly.
```
--------------------------------
### Migrate Formsnap `*Field*` components from slot props to snippet props in Svelte
Source: https://www.formsnap.dev/docs/v2-migration-guide
Formsnap v2 now provides access to `*Field*` component inner state (e.g., `value`, `errors`, `tainted`, `constraints`) via snippet props within the `children` snippet, replacing the previous slot prop mechanism. This requires wrapping your field content in a `{#snippet children({ ...props })}` block to access these values. If no state access is needed, the `children` snippet can be omitted.
```Svelte
```
```Svelte
{#snippet children({ value, errors, tainted, constraints })}
{/snippet}
```
--------------------------------
### Svelte: Implement useFormControl in a Custom Input Component
Source: https://www.formsnap.dev/docs/composition/use-form-control
This Svelte snippet demonstrates creating a `LabelInput.svelte` component that leverages `useFormControl` to access and apply control and label attributes to custom `CustomLabel` and `CustomInput` components. It illustrates how to build reusable form elements with advanced composition.
```Svelte
{label}
```
--------------------------------
### APIDOC: Fieldset Component Props
Source: https://www.formsnap.dev/docs/components/fieldset
Defines the properties accepted by the `Fieldset` component, including required form and name props, and optional ref, child, and rest attributes.
```APIDOC
Fieldset Component Props:
- form:
type: SuperForm
description: The form object returned from calling `superForm` in your component.
required: true
- name:
type: FormPath
description: The path to the field in the form object.
required: true
- ref:
type: HTMLElement | null
description: A $bindable reference to the underlying HTML element rendered by the `Fieldset` component.
- child:
type: Snippet
description: If provided, the `Fieldset` component will not render an HTML element and will instead expect you to spread the snippet's `props` onto an element of your choosing. See the `child` snippet documentation for more information.
- ...rest:
type: HTMLAttributes
description: Any additional props provided to the `Fieldset` component will be spread onto the underlying HTML element.
```
--------------------------------
### Formsnap Description Component Data Attributes
Source: https://www.formsnap.dev/docs/components/description
Lists the data attributes automatically applied to the `Description` component's underlying `` element, useful for styling or selection.
```APIDOC
Description Component Data Attributes:
- data-fs-description:
type: ''
description: Applied to the description element for selection during styling or otherwise.
- data-fs-error:
type: '' | undefined
description: Applied to the description element when a validation error exists on the field.
```
--------------------------------
### API Reference: Field Component Props
Source: https://www.formsnap.dev/docs/components/field
Documents the required props for the Formsnap `Field` component, including the form object from Superforms and the field's path.
```APIDOC
Class/Component: Field
Props:
form:
Type: SuperForm
Description: The form object returned from calling `superForm` in your component.
Required: true
name:
Type: FormPath
Description: The path to the field in the form object.
Required: true
```
--------------------------------
### ElementField Component Props API Reference
Source: https://www.formsnap.dev/docs/components/element-field
Defines the properties available for configuring the ElementField component. These props are essential for linking the component to a SuperForm instance and specifying the target field path within the form data structure.
```APIDOC
ElementField Props:
- form:
Type: SuperForm
Description: The form object returned from calling `superForm` in your component.
Required: true
- name:
Type: FormPathLeaves
Description: The path to the field in the form object.
Required: true
```
--------------------------------
### Legend Component Props Reference
Source: https://www.formsnap.dev/docs/components/legend
Documents the properties accepted by the Formsnap Legend component. This includes standard HTML