Datepicker enable range dates

I realized it's possible to create a datepicker with disabled dates, but it's possible to create a datepicker that has only specific dates available to select? Like if you have to select one of the available dates.
2 Replies
wyChoong
wyChoong15mo ago
No
dissto
dissto15mo ago
An example on how to disable weekends. @calebesantana
DatePicker::make('my_date')
->disabledDates(function () {
$start = Carbon::now();
$end = $start->copy()->addMonths(3);
$period = CarbonPeriod::create($start, $end);

$weekends = [];
foreach ($period as $date) {
if ($date->isWeekend()) {
$weekends[] = $date->format('Y-m-d');
}
}

return $weekends;
}),
DatePicker::make('my_date')
->disabledDates(function () {
$start = Carbon::now();
$end = $start->copy()->addMonths(3);
$period = CarbonPeriod::create($start, $end);

$weekends = [];
foreach ($period as $date) {
if ($date->isWeekend()) {
$weekends[] = $date->format('Y-m-d');
}
}

return $weekends;
}),
Essentially you can just return an array of dates to "disable". But you should still make sure to have the same in your validation as I believe the disableDates is only frontend
Want results from more Discord servers?
Add your server