F
Filamentβ€’15mo ago
Finn

Selecting only a year

Does Filament's datepicker offer an option for only years being able to be selected? Is this something that's better to do that with a different input type? My database column is a datatype of year(4). My current solution is:
TextInput::make('redacted_date_field')
->numeric()
->minValue(1900)
->maxValue(2100)
->hidden(fn(Get $get): bool => $get('redacted_bool_field') === false),
TextInput::make('redacted_date_field')
->numeric()
->minValue(1900)
->maxValue(2100)
->hidden(fn(Get $get): bool => $get('redacted_bool_field') === false),
Solution:
I would do like this Forms\Components\Select::make('year')->options(array_combine(range(2100, 1900), range(2100, 1900)))
Jump to solution
3 Replies
Solution
Vp
Vpβ€’15mo ago
I would do like this Forms\Components\Select::make('year')->options(array_combine(range(2100, 1900), range(2100, 1900)))
Finn
FinnOPβ€’15mo ago
I was looking for something like this but wasn't sure how to do it! Thanks πŸ™‚
Finn
FinnOPβ€’15mo ago
I ended up going for this:
Select::make('redacted_date_field')
->options(array_combine(range(now()->year, 1900), range(now()->year, 1900)))
->hidden(fn(Get $get): bool => $get('redacted_bool_field') === false),
Select::make('redacted_date_field')
->options(array_combine(range(now()->year, 1900), range(now()->year, 1900)))
->hidden(fn(Get $get): bool => $get('redacted_bool_field') === false),
Want results from more Discord servers?
Add your server