Form
High-performance form wrappers providing data collection, validation, and layout structures for form controls.
Wann zu verwenden
- Wenn Sie eine Instanz erstellen oder Informationen sammeln müssen.
- Wenn Sie Felder nach bestimmten Regeln validieren müssen.
Sign Up
Create an account to get started.
Basic Vertical Layout
The most common layout groups labels and controls vertically. Wrap each input inside a FormItem and a FormControl.
astro
---
import Form from '@/components/data-entry/Form.astro';
import FormItem from '@/components/data-entry/FormItem.astro';
import FormControl from '@/components/data-entry/FormControl.astro';
import TextInput from '@/components/data-entry/TextInput.astro';
import Button from '@/components/general/Button.astro';
---
<Form layout="vertical">
<FormItem label="Username" required help="This is your public display name.">
<FormControl>
<TextInput placeholder="johndoe" />
</FormControl>
</FormItem>
<FormItem label="Email" required error="Please enter a valid email address.">
<FormControl>
<TextInput placeholder="john@example.com" type="email" value="john" />
</FormControl>
</FormItem>
<FormItem>
<FormControl>
<Button type="submit">Submit</Button>
</FormControl>
</FormItem>
</Form> Horizontal Layout
When using layout="horizontal", labels and inputs are aligned horizontally, which is typical for dense settings pages.
astro
<Form layout="horizontal">
<FormItem label="First Name" layout="horizontal" required>
<FormControl>
<TextInput placeholder="Jane" />
</FormControl>
</FormItem>
<FormItem label="Role" layout="horizontal">
<FormControl>
<Select placeholder="Select a role">
<SelectOption value="admin">Admin</SelectOption>
<SelectOption value="user">User</SelectOption>
</Select>
</FormControl>
</FormItem>
<FormItem layout="horizontal">
<FormControl>
<Button type="button">Update Profile</Button>
</FormControl>
</FormItem>
</Form> Inline Layout
When using layout="inline", all form controls will align in a single row. This is perfect for simple inputs like search bars or newsletter signups.
astro
<Form layout="inline">
<FormItem>
<FormControl>
<TextInput placeholder="Search..." class="w-64" />
</FormControl>
</FormItem>
<FormItem>
<FormControl>
<Button type="button" variant="primary">Search</Button>
</FormControl>
</FormItem>
</Form> Form API
| Eigenschaft | Beschreibung | Typ | Standard |
|---|---|---|---|
| layout | Richtung des Formularlayouts | 'vertical' | 'horizontal' | 'inline' | 'vertical' |
FormItem API
| Eigenschaft | Beschreibung | Typ | Standard |
|---|---|---|---|
| layout | Richtung des Formularlayouts | 'vertical' | 'horizontal' | 'inline' | 'vertical' |
| label | Beschriftung für das Formularelement | string | undefined |
| required | Zeigt ein Sternchen (*) für erforderliche Felder an | boolean | false |
| help | Hilfetext unter der Eingabe | string | undefined |
| htmlFor | Die ID der Eingabe, die diese Beschriftung steuert | string | undefined |
| error | Indicates an error state or displays an error message | string | boolean | undefined |
| success | Indicates a success state or displays a success message | string | boolean | undefined |
| disabled | Disables the component | boolean | false |