Filament: Field Info in Prefix or Suffix - Dynamic Based on Value
2024-11-12 Filament v3Have you ever needed to show extra dynamic information based on the field value in “live” mode? You can do it using prefix/suffix, let's see how.

You need to:
- Make sure your field is
->live() - Add a closure with
Forms\Get $get - Retrieve the field using
$get('FIELD')function
This is how it looks:
Forms\Components\TextInput::make('price') ->label('Price (in cents)') ->numeric() ->live() ->suffix(function (Forms\Get $get) { return 'EUR ' . number_format($get('price') / 100, 2); }) ->required(),
And for Prefix, we do this:
Forms\Components\TextInput::make('price') ->label('Price (in cents)') ->numeric() ->live() ->prefix(function (Forms\Get $get) { return 'EUR ' . number_format($get('price') / 100, 2); }) ->required(),
A few of our Premium Examples: