ColumnSpan : Array to string conversion

Hello everyone, Is it only me who has this problem when I try to make my columns dynamic on any of my fields, I get the following error if I try to return an array from a closure: Array to string conversion Here is my code:
->columnSpan(function($get) {
return $get('show_time') ? [
'default' => 12,
'sm' => 12,
'md' => 3,
'lg' => 3,
'xl' => 3,
'2xl' => 3,
]:[
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
];
})
->columnSpan(function($get) {
return $get('show_time') ? [
'default' => 12,
'sm' => 12,
'md' => 3,
'lg' => 3,
'xl' => 3,
'2xl' => 3,
]:[
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
];
})
Whereas if I pass it an array directly without closure, I have no error. Is this a bug? Or am I the only one getting this problem?
5 Replies
awcodes
awcodes5mo ago
What is $get(‘show_time’) returning? If it’s anything other than true/false/null it will break your ternary.
Antoine
Antoine5mo ago
it's a Toggle and it returns true or false. I have the same error with :
->columnSpan(fn() => [
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
]),
->columnSpan(fn() => [
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
]),
and not error with :
->columnSpan([
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
]),
->columnSpan([
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
]),
So it's not the condition but I think it's the Closure...
awcodes
awcodes5mo ago
Sorry. Not sure then. Your code looks correct and the columnSpan method accepts a closure. Is this in a resource or a stand alone form.
Antoine
Antoine5mo ago
In a stand alone form, I tested in multi forms and I have the same error. Can you try in your app if this code on any field returns an error?
->columnSpan(fn() => [
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
]),
->columnSpan(fn() => [
'default' => 12,
'sm' => 12,
'md' => 9,
'lg' => 9,
'xl' => 9,
'2xl' => 9,
]),
I suspect a code bug in Filament or my entire application... Thank's for help!
awcodes
awcodes5mo ago
Make sure you are calling $this->form->fill() in the mount() method
Want results from more Discord servers?
Add your server
More Posts
Conditionally hiding the sidebar on specific pages/resourcesHi. Is it possible to conditionally collapse the sidebar on specific pages? I have a few pages wherCheck if filament is fully installed (can't log in, not related to canAccessPanel)Hey I have an issue that may be to the installation. My initial problem is that I can't log in (no,Error installing the filamentHello! I can't use filament allegedly because I didn't add to app.php AdminPanelProviderConditionally hide a sectionHi. Is it possible to conditionally hide a Section, based on another value on the form? E.g.: ```Rate Limiting Login Attempts in Filament V2 using Filament-Breezy and TenancyforlaravelHey there! I'm working on something with Filament V2 and using Filament-Breezy for the login stuffIs there a way to display empty table in TableWidget if specific property of parent model is false?I have created TableWidget inside which I have Table with custom query that pulls data from some extSPA mode in SafariHi, If I navigate on Safari in single page mode, it goes to a gray screens after a couple of clicksEdit Lifecycle hooks ->before is not workingHi, I'm trying to use the ->before() to add some logic to the record but is not being triggered. anyScope topbar / sidebar renderhooks to a specific panelIs there a way to scope topbar and sidebar renderhooks to a specific panel? CheersSpecific RelationManager does not showI have several relationship managers, but one of them has started not showing up, even though it jus