# Form Controls SvSeeds provides form controls as **Field components** such as `TextField`. All Field components share a unified structure and validation functionality. ## Basic Structure All Field components are composed of the following structured parts: ```text whole (div) - Overall wrapper ├─ top - Wrapper for label elements │ ├─ label - Label text │ ├─ extra - Label supplement (e.g., "optional") │ └─ aux - Additional information (e.g., character counter) ├─ middle - Input element wrapper │ └─ main - Input element (Only CheckField has a different structure) └─ bottom - Field description and error messages ``` Because `extra` is rendered inside the `label` element, it appears only when `label` is set; provide `label` whenever you use `extra`. ### Design Rationale We use a `div` element for the `whole` container. We avoid using `fieldset` elements because they render an [anonymous fieldset content box](https://html.spec.whatwg.org/multipage/rendering.html#anonymous-fieldset-content-box), which complicates styling. ## Validation Features Field components provide built-in validation functionality. ### Validation Function Type Definitions TypeScript type definitions are provided for each Field component. Please refer to the individual component documentation for details. ### Validation Patterns Field components support three validation patterns: #### 1. Using Custom Functions Validation runs immediately after user input. No validation occurs when the field value(s) is empty. ```svelte ``` #### 2. Using Attributes + Custom Functions You can combine validation attributes with custom error messages. ```svelte ``` #### 3. Browser Native Validation Standard browser validation messages are displayed during form submission. ```svelte ``` ## Variant Transitions The `variant` prop automatically transitions based on input state: - `neutral` - Initial state or empty state - `inactive` - Validation failed state - `active` - Validation passed state ## Form-wide Validation ### Basic Pattern When validating multiple Field components simultaneously, use a `form` element: ```svelte
``` ### Integration with Button Component Using SvSeeds' Button component allows for more concise code. When `onclick` is set on a Button, it only runs if `form?.checkValidity()` returns `true`. ```svelte
``` ## Form Submission To submit form data, set the `name` attribute directly on each Field component: ```svelte
```