F
Filament12mo 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 Sese12mo ago
I believe min and max are just for validation. Try ->disabledDates()
Abi
AbiOP12mo ago
ah ok
Kenneth Sese
Kenneth Sese12mo ago
It accepts an array of dates or a closure
Abi
AbiOP12mo 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 Sese12mo ago
Actually, try using minDate and maxDate but with ->native(false)
Noor
Noor12mo 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 Sese12mo ago
That only does a few dates, ->native(false) should do what he wants
Abi
AbiOP12mo ago
I actually want the opposite, I only want few dates enabled and the rest disabled..
Kenneth Sese
Kenneth Sese12mo 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 Sese12mo 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 Sese12mo ago
Abi
AbiOP12mo ago
thank you. that worked
Want results from more Discord servers?
Add your server