F
Filament2y ago
Abi

`visible()` method doesn't work right with === check.

Here is the code snippet I have
Select::make('table_style')
->options([
0 => 'Default',
1 => 'Style 1',
2 => 'Style 2',
])->reactive()->required(),

Section::make('Default Settings')
->schema([
Toggle::make('show_features')
->inline(false),
])->visible(fn(\Closure $get) => $get('table_style') == 0),

Section::make('Style 2 Settings')
->schema([
Toggle::make('show_features')
->inline(false),
])->visible(fn(\Closure $get) => $get('table_style') === 1),

Section::make('Style 3 Settings')
->schema([
Toggle::make('show_features')
->inline(false),
])->visible(fn(\Closure $get) => $get('table_style') === 2),
Select::make('table_style')
->options([
0 => 'Default',
1 => 'Style 1',
2 => 'Style 2',
])->reactive()->required(),

Section::make('Default Settings')
->schema([
Toggle::make('show_features')
->inline(false),
])->visible(fn(\Closure $get) => $get('table_style') == 0),

Section::make('Style 2 Settings')
->schema([
Toggle::make('show_features')
->inline(false),
])->visible(fn(\Closure $get) => $get('table_style') === 1),

Section::make('Style 3 Settings')
->schema([
Toggle::make('show_features')
->inline(false),
])->visible(fn(\Closure $get) => $get('table_style') === 2),
If I use === to check the visible condition, it doesn't work. But the same works with ==. Am i missing something? The key's on the Select fields are integer and I am checking against an integer.
3 Replies
wyChoong
wyChoong2y ago
it is likely when retrieved the value back from the html select is returned as string can easily solve by ->visible(fn(\Closure $get) => (int) $get('table_style') == 0),
Abi
AbiOP2y ago
ok
toeknee
toeknee2y ago
You need to type cast, $get pulls all strings, so you would need to either (int) or quote the number so it's string to string.
Want results from more Discord servers?
Add your server