0

I'm working on a Laravel project using Filamentphp
My form has DatePicker and I'm unable to disable all Weekends days or disable all dates except the one I specify.

enter image description here

 DatePicker::make('issue_start_date')
                              ->required()
                              ->reactive()
                              ->weekStartsOnSunday()
                              ->afterStateUpdated(function (callable $set, $state)
                              {
                                  $month = date('M', strtotime($state));
                                  $year  = date('Y', strtotime($state));
                                  ($month == null || $year === null)
                                      ? $set('name', null)
                                      : $set('name', $month . ' ' . $year);
                              })
                              ->dehydrateStateUsing(function (callable $set, $state)
                              {
                                  if ($state === null) $set('name', null);
                              }),

Appreciate if someone can help me to solve this problem

Amir Hussain
  • 47
  • 1
  • 8

1 Answers1

0

you can use disabledDates option to disable dates based on the requirements.

below is an example of disabledDates

DatePicker::make('issue_start_date')
    ->required()
    ->reactive()
    ->weekStartsOnSunday()
    ->afterStateUpdated(function (callable $set, $state)
    {
        $month = date('M', strtotime($state));
        $year  = date('Y', strtotime($state));
        ($month == null || $year === null)
            ? $set('name', null)
            : $set('name', $month . ' ' . $year);
    })
    ->dehydrateStateUsing(function (callable $set, $state)
    {
        if ($state === null) $set('name', null);
    })
    ->disabledDates([
        // Disable all weekends
        'Sat', 'Sun',
        // Disable dates before today
        'before ' . now()->format('Y-m-d'),
        // Disable dates after 5 days from now
        'after ' . now()->addDays(5)->format('Y-m-d'),
    ]);

You can disable all weekends in the Filamentphp calendar by using the events function in your calendar configuration. This function allows you to add custom events to the calendar, including disabling specific dates.

->events([
    [
        'title' => 'Weekend',
        'start' => Carbon::parse('saturday'),
        'end' => Carbon::parse('sunday'),
        'display' => 'background',
    ],
]);
Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39