The Field class is the foundation for all form input components in Filament. It extends the base Component class and provides form-specific functionality including validation, labels, hints, and helper text.
Namespace
Filament\Forms\Components\Field
Inheritance
Extends: Filament\Schemas\Components\Component
Implements: Contracts\HasValidationRules
Static Methods
make()
Create a new field instance.
public static function make(?string $name = null): static
The field name. This is used for data binding and as the state path. If null, the field class must define getDefaultName().
Returns the field instance for method chaining.
Example:
use Filament\Forms\Components\TextInput;
TextInput::make('email')
->email()
->required();
getDefaultName()
Get the default name for the field when not explicitly provided.
public static function getDefaultName(): ?string
Returns the default name or null.
Instance Methods
getLabel()
Get the field label.
public function getLabel(): string | Htmlable | null
Returns the field label. If not set, generates a default label from the field name.
getDefaultLabel()
Get the auto-generated default label.
public function getDefaultLabel(): string
Returns the label generated from the field name.
Example:
// Field name 'first_name' generates label 'First name'
// Field name 'customer.email' generates label 'Email'
aboveLabel()
Add components above the field label.
public function aboveLabel(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render above the label.
Returns the field instance for method chaining.
belowLabel()
Add components below the field label.
public function belowLabel(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render below the label.
Returns the field instance for method chaining.
beforeLabel()
Add components before the field label (inline).
public function beforeLabel(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render before the label.
Returns the field instance for method chaining.
afterLabel()
Add components after the field label (inline).
public function afterLabel(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render after the label.
Returns the field instance for method chaining.
aboveContent()
Add components above the field content.
public function aboveContent(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render above the content.
Returns the field instance for method chaining.
belowContent()
Add components below the field content.
public function belowContent(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render below the content.
Returns the field instance for method chaining.
beforeContent()
Add components before the field content (inline).
public function beforeContent(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render before the content.
Returns the field instance for method chaining.
afterContent()
Add components after the field content (inline).
public function afterContent(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render after the content.
Returns the field instance for method chaining.
aboveErrorMessage()
Add components above validation error messages.
public function aboveErrorMessage(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render above error messages.
Returns the field instance for method chaining.
belowErrorMessage()
Add components below validation error messages.
public function belowErrorMessage(
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null $components
): static
components
array | Schema | Component | Action | ActionGroup | string | Htmlable | Closure | null
Components to render below error messages.
Returns the field instance for method chaining.
hasNullableBooleanState()
Check if this field has a nullable boolean state.
public function hasNullableBooleanState(): bool
Returns true if the field supports nullable boolean values.
getDefaultStateCasts()
Get the default state casts for this field.
public function getDefaultStateCasts(): array
Returns an array of state cast instances.
Schema Keys
The Field class defines several schema keys for positioning child components:
const ABOVE_LABEL_SCHEMA_KEY = 'above_label';
const BELOW_LABEL_SCHEMA_KEY = 'below_label';
const BEFORE_LABEL_SCHEMA_KEY = 'before_label';
const AFTER_LABEL_SCHEMA_KEY = 'after_label';
const ABOVE_CONTENT_SCHEMA_KEY = 'above_content';
const BELOW_CONTENT_SCHEMA_KEY = 'below_content';
const BEFORE_CONTENT_SCHEMA_KEY = 'before_content';
const AFTER_CONTENT_SCHEMA_KEY = 'after_content';
const ABOVE_ERROR_MESSAGE_SCHEMA_KEY = 'above_error_message';
const BELOW_ERROR_MESSAGE_SCHEMA_KEY = 'below_error_message';
Traits
The Field class uses multiple traits for additional functionality:
CanBeAutofocused - Autofocus support
CanBeMarkedAsRequired - Required field marking
CanBeValidated - Validation rules
HasEnum - Enum support
HasExtraFieldWrapperAttributes - Additional wrapper attributes
HasHelperText - Helper text below the field
HasHint - Hint text next to the label
HasLabel - Label configuration
HasName - Field name configuration
Common Field Methods
Inherited from traits:
Validation
->required()
->email()
->numeric()
->minLength(10)
->maxLength(255)
->rules(['required', 'string'])
Labels and Hints
->label('Email Address')
->helperText('We will never share your email')
->hint('Optional')
->hintIcon('heroicon-o-question-mark-circle')
State
->default('default value')
->afterStateUpdated(fn ($state) => /* ... */)
->live() // Update on every change
->dehydrated(false) // Exclude from form data