Skip to main content

Introduction

Filament forms are built on Livewire, enabling powerful reactive behavior without writing JavaScript. This guide covers advanced features like reactive fields, dependent field logic, field lifecycle hooks, and performance optimization.

Reactive forms

The basics of reactivity

By default, forms don’t re-render when field values change. This is a performance optimization since rendering requires a server round-trip. To make a field reactive, use the live() method:

Reactive on blur

For text inputs, validate after the user finishes typing:

Debounced reactivity

Wait for the user to stop typing before triggering updates:

Dependent fields

Conditional visibility

Show or hide fields based on other field values:

Conditional requirements

Make fields required based on conditions:

Conditional disabling

Dynamic field options

Field lifecycle hooks

After state hydrated

Runs when the form is filled with data:
Or use the shortcut:

After state updated

Runs when the user changes a field:

Before state dehydrated

Runs before form data is saved:

Advanced reactive patterns

Auto-generating slugs

Calculated totals

Dependent repeaters

Wizard with conditional steps

Performance optimization

Avoiding unnecessary re-renders

Use JavaScript expressions for simple UI updates:

Selective field rendering

Only re-render specific fields:

Dehydration control

Prevent fields from being saved:

Using JavaScript utilities

JavaScript expressions in labels

Accessing field state in JavaScript

The $get() and $state utilities are available in JavaScript contexts:

Field state management

Getting field values

Setting field values

Calling updated hooks

By default, $set() doesn’t trigger afterStateUpdated() hooks. To trigger them:

Complex form patterns

Multi-step validation

Dynamic field schema

Conditional field groups

Best practices

Performance

  • Use live(onBlur: true) for text inputs to reduce requests
  • Use live(debounce: 500) for real-time validation with typing
  • Avoid deep nesting of reactive fields
  • Use JavaScript expressions for simple calculations

User experience

  • Provide immediate feedback for validation errors
  • Use debouncing to avoid jarring UI updates
  • Show loading states during async operations
  • Clear dependent fields when their parent changes

Code organization

  • Extract complex logic into dedicated methods
  • Use form components to reuse field patterns
  • Document complex reactive relationships
  • Test edge cases thoroughly

Security

  • Always validate on the backend
  • Don’t rely solely on frontend validation
  • Sanitize user input before setting field values
  • Be cautious with dynamic field schemas

Next steps