F
Filament8mo ago
aidzis

Section with reactive fields forces collapse after field value changes.

I have a use case where I would want the heading of Section to reflect values of fields under it. This is so I can use Section as collapsed by default to save screen space. The issue is that with this setup:
Section::make(function (array $state) {
if (! $state['test']) {
return 'TEST';
}

return 'Test: ' . $state['test'];
})
->collapsible()
->collapsed()
->schema([
TextInput::make('test')
->reactive(),
])
Section::make(function (array $state) {
if (! $state['test']) {
return 'TEST';
}

return 'Test: ' . $state['test'];
})
->collapsible()
->collapsed()
->schema([
TextInput::make('test')
->reactive(),
])
Auto collapse is forced after each state update. Here is a video https://www.loom.com/share/9559899844ed4e3480d7af0cb7add516 Any ideas how I could resolve this?
6 Replies
aidzis
aidzisOP8mo ago
Looks like ->description() has no issues with this. I will be using that for now. Still interested on what coould cause this issue with the heading
Ozumat77
Ozumat778mo ago
What happens when you use ->live() instead of ->reactive() ?
aidzis
aidzisOP8mo ago
Same thing happns with ->live() or ->lazy()
MohamedSabil83
MohamedSabil838mo ago
try to add the code to ->heading()
aidzis
aidzisOP8mo ago
oh forgot to mention this, but I tried it on heading() instead of make, same result
awcodes
awcodes8mo ago
You need to do a check inside ->collapsed() what is happening is that ->live() causes a refresh of the component that you have told to be collapsed. So when it rerenders it will always be collapsed.
Want results from more Discord servers?
Add your server