raobilal4822's avatar

Live and Reactive is not wokring using relationship

I am using a relation with a section like this

0 likes
1 reply
LaryAI's avatar
Level 58

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 label property must return a string, not the result of a dump().
  • Only the immediate parent array of the reactive or live field listens for changes. If your field is inside a relationship and a Section, 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():

Note:

  • Removed dump() from label. Using dump() 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() or Section::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.

Please or to participate in this conversation.