F
Filament7mo ago
Abi

DatePicker not disabling dates outside of min and max dates

I have the following code to create a DatePicker for Table Filter
$minDate = Carbon::parse('12/26/2023');
$minDate = Carbon::parse('12/28/2023');
DatePicker::make('created_from')
->default(Carbon::now())
->minDate($minDate)
->maxDate($maxDate),
$minDate = Carbon::parse('12/26/2023');
$minDate = Carbon::parse('12/28/2023');
DatePicker::make('created_from')
->default(Carbon::now())
->minDate($minDate)
->maxDate($maxDate),
but the dates outside of min and max dates don't seem to be disabled. Am I missing something here?
Solution:
POC: ```php Forms\Components\DatePicker::make('poc_date') ->minDate(now()->startOfMonth()->addDay()) ->maxDate(now()->endOfMonth()->subDay())...
Jump to solution
13 Replies
Kenneth Sese
Kenneth Sese7mo ago
I believe min and max are just for validation. Try ->disabledDates()
Abi
Abi7mo ago
ah ok
Kenneth Sese
Kenneth Sese7mo ago
It accepts an array of dates or a closure
Abi
Abi7mo ago
can't disabled all dates except a few with that if I am right. :). Not sure what the closure would be..
Kenneth Sese
Kenneth Sese7mo ago
Actually, try using minDate and maxDate but with ->native(false)
Noor
Noor7mo ago
Disabling specific dates
->disabledDates(['2000-01-03', '2000-01-15', '2000-01-20'])
->disabledDates(['2000-01-03', '2000-01-15', '2000-01-20'])
Kenneth Sese
Kenneth Sese7mo ago
That only does a few dates, ->native(false) should do what he wants
Abi
Abi7mo ago
I actually want the opposite, I only want few dates enabled and the rest disabled..
Kenneth Sese
Kenneth Sese7mo ago
Yes, so use your original code but add ->native(false). That’ll disable everything before/after those dates You can then use ->disabledDates() along with that if you want to disable weekends, or holidays or something like that (Also, in your original code you are setting minDate twice)
Solution
Kenneth Sese
Kenneth Sese7mo ago
POC:
Forms\Components\DatePicker::make('poc_date')
->minDate(now()->startOfMonth()->addDay())
->maxDate(now()->endOfMonth()->subDay())
->disabledDates(['2023-12-9', '2023-12-10'])
->native(false),
Forms\Components\DatePicker::make('poc_date')
->minDate(now()->startOfMonth()->addDay())
->maxDate(now()->endOfMonth()->subDay())
->disabledDates(['2023-12-9', '2023-12-10'])
->native(false),
will get you this:
Kenneth Sese
Kenneth Sese7mo ago
Abi
Abi7mo ago
thank you. that worked