F
Filamentβ€’9mo ago
Chrysippus

Hide Select Dropdown depends on the Select Dropdown value?

Hello, I want to hide a specific Select Dropdown something like this using afterStateUpdated() ,is this possible? any suggestion to make this work with or without using afterStateUpdated?
Select::make('type')
->required()
->options([
'normal' => 'Normal',
'service' => 'Service',
'tier' => 'Tier',
])
->default('normal')
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Forms\Set $set, Forms\Get $get) {
if ($state == 'tier'){
// show tier column
}
}),
Select::make('tier')
->required()
->options([
1 => 'Tier 1',
2 => 'Tier 2',
3 => 'Tier 3',
])
->default(1)
Select::make('type')
->required()
->options([
'normal' => 'Normal',
'service' => 'Service',
'tier' => 'Tier',
])
->default('normal')
->live(onBlur: true)
->afterStateUpdated(function (string $operation, $state, Forms\Set $set, Forms\Get $get) {
if ($state == 'tier'){
// show tier column
}
}),
Select::make('tier')
->required()
->options([
1 => 'Tier 1',
2 => 'Tier 2',
3 => 'Tier 3',
])
->default(1)
TIA πŸ™
2 Replies
Chrysippus
ChrysippusOPβ€’9mo ago
oh its working now using hidden()
Select::make('type')
->required()
->options([
'normal' => 'Normal',
'service' => 'Service',
'tier' => 'Tier',
])
->default('normal'),
Select::make('tier')
->required()
->hidden(function (string $operation, $state, Forms\Set $set, Forms\Get $get) {
if ($get('type') == 'tier'){
return false;
} else {
return true;
}
})
->options([
1 => 'Tier 1',
2 => 'Tier 2',
3 => 'Tier 3',
])
->default(1),
Select::make('type')
->required()
->options([
'normal' => 'Normal',
'service' => 'Service',
'tier' => 'Tier',
])
->default('normal'),
Select::make('tier')
->required()
->hidden(function (string $operation, $state, Forms\Set $set, Forms\Get $get) {
if ($get('type') == 'tier'){
return false;
} else {
return true;
}
})
->options([
1 => 'Tier 1',
2 => 'Tier 2',
3 => 'Tier 3',
])
->default(1),
Brian.
Brian.β€’9mo ago
You can make it even more compact using:
->hidden(fn ($get): bool => $get('type') == 'tier')
->hidden(fn ($get): bool => $get('type') == 'tier')
Want results from more Discord servers?
Add your server