Update TextInput based on Select value

I have two fields:
Select::make('job_salary_type')
->columnSpanFull()
->label(__('strings.fields.job_salary_type'))
->live()
->default(0)
->options([
0 => __('strings.strings.unknown'),
1 => __('strings.strings.monthly'),
2 => __('strings.strings.yearly'),
]),

TextInput::make('job_salary_avg')
->hidden(function ($get) {
return $get('job_salary_type') === 0;
})
->numeric()
->prefix('€')
->label(__('strings.fields.job_salary_avg'))
->helperText(function ($get) {
$helperText = __(
'strings.strings.average_salary',
['type' => __('strings.strings.per_month')]
);
if ($get('job_salary_type') === 2) {
$helperText = __(
'strings.strings.average_salary',
['type' => __('strings.strings.per_year')]
);
}

return $helperText;
}),
Select::make('job_salary_type')
->columnSpanFull()
->label(__('strings.fields.job_salary_type'))
->live()
->default(0)
->options([
0 => __('strings.strings.unknown'),
1 => __('strings.strings.monthly'),
2 => __('strings.strings.yearly'),
]),

TextInput::make('job_salary_avg')
->hidden(function ($get) {
return $get('job_salary_type') === 0;
})
->numeric()
->prefix('€')
->label(__('strings.fields.job_salary_avg'))
->helperText(function ($get) {
$helperText = __(
'strings.strings.average_salary',
['type' => __('strings.strings.per_month')]
);
if ($get('job_salary_type') === 2) {
$helperText = __(
'strings.strings.average_salary',
['type' => __('strings.strings.per_year')]
);
}

return $helperText;
}),
I would expect that the field would hide if I select option 0 in my Select component. This is not happening. Any ideas what I'm missing here?
2 Replies
Nate
Nate12mo ago
Does typecasting it help since then it will know what to inject?
use Filament\Forms\Get;

->hidden(fn(Get $get) => $get('job_salary_type') === 0),
use Filament\Forms\Get;

->hidden(fn(Get $get) => $get('job_salary_type') === 0),
Daniel Plomp
Daniel PlompOP12mo ago
No, same result unfortunately.
Want results from more Discord servers?
Add your server