Certainly! Here’s a focused explanation and solution for why your live and reactive behaviors aren’t updating as expected for your form field label in FilamentPHP:
Problem Summary
You have a Select field (let_intro_fee_type) that should update a TextInput label and suffix reactively based on the selected type ("percentage" or "fixed"). You're using Filament's ->live() and ->reactive() methods, but the label isn’t updating as intended.
Solution
Key Points:
- The closure for the
labelproperty must return a string, not the result of adump(). - Only the immediate parent array of the reactive or live field listens for changes. If your field is inside a
relationshipand aSection, ensure you use ->reactive() on the section/array as well. - In many Filament situations, you need ->reactive() on both the Select and also the parent schema (sometimes even the section or group), to enable this two-way re-rendering.
Example Solution
Check that:
- Your section or group is reactive.
- Your field callback only returns a string.
- You chain
->reactive()and->live()on Select.
Here’s a corrected version for your getLetinroFields():
public static function getLetinroFields(): array
{
$currency = CurrencyTypeEnum::tryFrom(auth()->user()?->company?->default_currency) ?? CurrencyTypeEnum::POUNDS;
return [
Hidden::make('created_by')
->default(auth()->user()?->id),
Select::make('let_intro_fee_type')
->live()
->reactive()
->label('Let Intro Fee')
->options([
'percentage' => 'Percentage',
'fixed' => 'Fixed Amount',
])
->default('percentage')
->columnSpan(1),
TextInput::make('let_intro_fee_value')
->label(fn (Get $get) =>
$get('let_intro_fee_type') === 'percentage'
? 'Percentage (%)'
: 'Amount'
)
->numeric()
->suffix(fn (Get $get) =>
$get('let_intro_fee_type') === 'percentage'
? '%'
: ($currency->value ?? null)
)
->columnSpan(1),
];
}
Note:
- Removed
dump()from label. Usingdump()prevents a proper string return. - If this still does not work, wrap the fields in Group::make([...])->reactive() or Section::make([...])->reactive() so the reactive context is maintained.
Ensuring Reactivity in Relationships
If your relationship's schema is in a Section, make it reactive too:
Section::make('Commission')
->relationship('commissionSetup')
->schema(function (Get $get, $record) use ($serviceLevel) {
// your existing logic...
})
->columns(2)
->reactive() // <--- Add this
->visible( ... );
Or, if you’re returning fields in an array, wrap them in a Group and set it as reactive:
Group::make([
// fields here
])->reactive()
Summary Checklist
- Use
->reactive()on Select and on the parent (Section/Group) if you do dynamic fields. - Your closure for label/suffix must return a string (no dump/print/etc.).
-
->live()is only needed for Select fields that should trigger parent refreshes. - Wrap dynamically changing arrays in a
Group::make()->reactive()orSection::make()->reactive()if needed.
Final Advice
Make these changes and it will work as intended! If you keep having issues, simplify the reactive test to just change a plain text field and verify the update first, then expand to suffix/label.
Let me know if you need a more direct example with your exact parent structure.