61 lines
1.7 KiB
Markdown
Raw Normal View History

2025-12-18 01:11:17 +00:00
# Form Fragments & Composition
Reusable form components and modular form building.
## Files
### Fragments (Reusable Components)
- **header.toml** - Header/intro section
- **custom_border_section.toml** - Styled section template
- **fancy_border_section.toml** - Advanced border styling
- **employee_info_section.toml** - Employee data fields
- **agreement_section.toml** - Legal/policy acceptance
- **support_section.toml** - Support tier selection
- **premium_section.toml** - Premium features section
- **enterprise_section.toml** - Enterprise tier section
### Examples Using Fragments
- **form_with_groups_includes.toml** - Demonstrates fragment inclusion
## Usage Pattern
### Include Fragments in Your Forms
```toml
# main_form.toml
[includes]
header = "fragments/header.toml"
employee = "fragments/employee_info_section.toml"
agreement = "fragments/agreement_section.toml"
[sections.main]
title = "Employee Onboarding"
```
### Build Complex Forms from Reusable Parts
```bash
# Each fragment can be tested independently
cargo run --example form_with_groups_includes
```
## Benefits
- **DRY** - Write common sections once
- **Maintainability** - Update fragments in one place
- **Reusability** - Share across multiple forms
- **Modularity** - Compose complex forms from simple parts
- **Consistency** - Unified styling and structure
## Fragment Library
Use these as templates for your own fragments:
| Fragment | Purpose | Fields |
|----------|---------|--------|
| header | Form introduction | Title, description |
| employee_info | Standard employee data | Name, email, phone |
| agreement | Policy acceptance | Checkbox, text |
| support | Tier selection | Radio buttons |
| border_section | Custom styled container | Any fields |