Conditionally display a section, based on another field's value

How can you conditionally display a section based on another field's value?
6 Replies
toeknee
toeknee3mo ago
->visible(fn($get) => $get('field_name') === 'value to hide on')
->visible(fn($get) => $get('field_name') === 'value to hide on')
atabegruslan
atabegruslanOP3mo ago
Thank you
atabegruslan
atabegruslanOP3mo ago
And a related question In a infolist RepeatableEntry I only want to display when its a certain type
Components\Section::make()->schema([
Components\RepeatableEntry::make('relation')
->schema([
Components\TextEntry::make('field')->visible(fn($record) => $record->type === 'xxx'),
])
])
Components\Section::make()->schema([
Components\RepeatableEntry::make('relation')
->schema([
Components\TextEntry::make('field')->visible(fn($record) => $record->type === 'xxx'),
])
])
But when I do it this way, I end up with something that look like the screenshot (with empty sections)
No description
atabegruslan
atabegruslanOP3mo ago
Is there a better way?
LeandroFerreira
LeandroFerreira3mo ago
maybe using the same condition in the Section?
atabegruslan
atabegruslanOP3mo ago
No. I tried something else too, but still same result (with an empty section). Below is Filament Resource for Delivery model, infolist function:
Components\RepeatableEntry::make('order.addresses') // <---- There's 2 types of addresses: Shipping and Billing
->schema([
Components\TextEntry::make('address_line_1')
]) // <--- If I use "->visible(fn($record) => ...)" here, $record is not the Address object (which is a problem), it's actually the Delivery model
Components\RepeatableEntry::make('order.addresses') // <---- There's 2 types of addresses: Shipping and Billing
->schema([
Components\TextEntry::make('address_line_1')
]) // <--- If I use "->visible(fn($record) => ...)" here, $record is not the Address object (which is a problem), it's actually the Delivery model
PS: Delivery is associated with an Order. Order is associated with a pair of Addresses, like $delivery->order->addresses
Want results from more Discord servers?
Add your server