# Form Components The Admin package provides a comprehensive set of form components with consistent styling, validation, and authorization support. ## Overview All form components: - Follow consistent design patterns - Support Laravel validation - Include accessibility attributes (ARIA) - Work with Livewire - Support authorization props ## Form Group Wrapper component for labels, inputs, and validation errors: ```blade ``` **Props:** - `label` (string) - Field label - `name` (string) - Field name for validation errors - `required` (bool) - Show required indicator - `help` (string) - Help text below field - `error` (string) - Manual error message ## Input Text input with various types: ```blade {{-- Text input --}} {{-- Email input --}} {{-- Password input --}} {{-- Number input --}} {{-- Date input --}} ``` **Props:** - `name` (string, required) - Input name - `label` (string) - Label text - `type` (string) - Input type (text, email, password, number, date, etc.) - `value` (string) - Input value - `placeholder` (string) - Placeholder text - `required` (bool) - Required field - `disabled` (bool) - Disabled state - `readonly` (bool) - Read-only state - `min` / `max` (number) - Min/max for number inputs ## Textarea Multi-line text input: ```blade {{-- With character counter --}} ``` **Props:** - `name` (string, required) - Textarea name - `label` (string) - Label text - `rows` (number) - Number of rows (default: 5) - `cols` (number) - Number of columns - `placeholder` (string) - Placeholder text - `maxlength` (number) - Maximum character length - `show-counter` (bool) - Show character counter - `required` (bool) - Required field ## Select Dropdown select: ```blade {{-- Simple select --}} {{-- With placeholder --}} {{-- Multiple select --}} {{-- Grouped options --}} ``` **Props:** - `name` (string, required) - Select name - `label` (string) - Label text - `options` (array, required) - Options array - `value` (mixed) - Selected value(s) - `placeholder` (string) - Placeholder option - `multiple` (bool) - Allow multiple selections - `required` (bool) - Required field - `disabled` (bool) - Disabled state ## Checkbox Single checkbox: ```blade {{-- With description --}} {{-- Group of checkboxes --}}
Permissions
``` **Props:** - `name` (string, required) - Checkbox name - `label` (string) - Label text - `value` (string) - Checkbox value - `checked` (bool) - Checked state - `description` (string) - Help text below checkbox - `disabled` (bool) - Disabled state ## Toggle Switch-style toggle: ```blade {{-- With colors --}} ``` **Props:** - `name` (string, required) - Toggle name - `label` (string) - Label text - `checked` (bool) - Checked state - `description` (string) - Help text - `color` (string) - Toggle color (green, blue, red) - `disabled` (bool) - Disabled state ## Button Action buttons with variants: ```blade {{-- Primary button --}} Save Changes {{-- Secondary button --}} Cancel {{-- Danger button --}} Delete Post {{-- Ghost button --}} Reset {{-- Icon button --}} {{-- Loading state --}} Save Saving... ``` **Props:** - `type` (string) - Button type (button, submit, reset) - `variant` (string) - Style variant (primary, secondary, danger, ghost, icon) - `href` (string) - Link URL (renders as ``) - `loading` (bool) - Show loading state - `disabled` (bool) - Disabled state - `size` (string) - Size (sm, md, lg) ## Authorization Props All form components support authorization attributes: ```blade Create Post Delete ``` **Authorization Props:** - `can` (string) - Gate/policy check - `can-arguments` (array) - Arguments for gate check - `cannot` (string) - Inverse of `can` - `hidden-unless` (string) - Hide element unless authorized - `readonly-unless` (string) - Make readonly unless authorized - `disabled-unless` (string) - Disable unless authorized [Learn more about Authorization →](/packages/admin/authorization) ## Livewire Integration All components work seamlessly with Livewire: ```blade
Save Post ``` ### Real-Time Validation ```blade @error('slug')

{{ $message }}

@enderror ``` ### Debounced Input ```blade ``` ## Validation Components automatically show validation errors: ```blade {{-- Controller validation --}} $request->validate([ 'title' => 'required|max:255', 'content' => 'required', 'status' => 'required|in:draft,published', ]); {{-- Blade template --}} {{-- Validation errors automatically displayed --}} ``` ### Custom Error Messages ```blade ``` ## Complete Form Example ```blade
@csrf
{{-- Title --}} {{-- Slug --}} {{-- Content --}} {{-- Status --}} {{-- Category --}} {{-- Options --}}
{{-- Actions --}}
Save Post Cancel Delete
``` ## Styling Components use Tailwind CSS and can be customized: ```blade ``` ### Custom Wrapper Classes ```blade ``` ## Best Practices ### 1. Always Use Form Groups ```blade {{-- ✅ Good - wrapped in form-group --}} {{-- ❌ Bad - no form-group --}} ``` ### 2. Use Old Values ```blade {{-- ✅ Good - preserves input on validation errors --}} {{-- ❌ Bad - loses input on validation errors --}} ``` ### 3. Provide Helpful Placeholders ```blade {{-- ✅ Good - clear placeholder --}} {{-- ❌ Bad - vague placeholder --}} ``` ### 4. Use Authorization Props ```blade {{-- ✅ Good - respects permissions --}} Delete ``` ## Learn More - [Livewire Modals →](/packages/admin/modals) - [Authorization →](/packages/admin/authorization) - [HLCRF Layouts →](/packages/admin/hlcrf)