F
Filament2y ago
RMH

Single entry from DatePicker or DateTimePicker

Is it possible to select only one field from DatePicker or DateTimePicker like only month or only year?
6 Replies
Patrick Boivin
Hi @ranamoizhaider , can you describe the behavior you are looking for? What do you want to see/click in the datepicker, and what do you want to appear in the text input?
RMH
RMHOP2y ago
I am generating a challan and I have a field named challan_for this field will only have the value of month. Now one approach that I can go with is:
Forms\Components\Select::make('challan_for')
->options([
'January',
'February',
...
]),
Forms\Components\Select::make('challan_for')
->options([
'January',
'February',
...
]),
I was asking is there any way to select only month or month and year from datepicker (I mean without selecting date). Like we open and only this appears(image attached).
RMH
RMHOP2y ago
Maybe something like:
Forms\Components\DatePicker::make('challan_for')->fields(['Month', 'Year'])->default(now());
Forms\Components\DatePicker::make('challan_for')->fields(['Month', 'Year'])->default(now());
Patrick Boivin
I see, thanks for the details! I don't think this is possible with the DatePicker field but, on the other hand, it would be pretty simple to use 2 Select fields. How are you saving this info in the database?
RMH
RMHOP2y ago
I was trying to save it as a string. Now I have changed it to two select fields as you suggested challan_month and challan_year and using two select fields. Both of these are strings.
basilio73
basilio7312mo ago
You can do it with FlatPickr Plugin: https://filamentphp.com/plugins/coolsam-flatpickr . But I'm having some issues with it right now
Filament
Flatpickr by Sam Maosa - Filament
Use Flatpickr as your datepicker in the Filament Forms and Panels
Want results from more Discord servers?
Add your server