Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

Filament: Field Info in Prefix or Suffix - Dynamic Based on Value

2024-11-12

Have 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:

  1. Make sure your field is ->live()
  2. Add a closure with Forms\Get $get
  3. 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: