F
Filament3mo 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
aidzis3mo 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
Ozumat773mo ago
What happens when you use ->live() instead of ->reactive() ?
aidzis
aidzis3mo ago
Same thing happns with ->live() or ->lazy()
MohamedSabil83
MohamedSabil833mo ago
try to add the code to ->heading()
aidzis
aidzis3mo ago
oh forgot to mention this, but I tried it on heading() instead of make, same result
awcodes
awcodes3mo 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
More Posts