FilamentF
Filament16mo ago
nowak

Is it possible to add validation to a `Action::make()` before opening the confirmation modal?

I have added a header action to my table, where I have tried to add validation in the ->before() lifecycle hook:
Action::make('acceptAll')
  ->before(function ($action, $livewire) {
    Log::debug('Before hook');
    $groupOrders = $livewire->getTableRecords();
    foreach ($groupOrders as $groupOrder) {
      if (!$groupOrder->courier) {
        Notification::make()
          ->warning()
          ->title('Missing Courier')
          ->body('Group order with route ID ' . $groupOrder->route->id . ' does not have a courier assigned. Please assign a courier and try again.')
          ->persistent()
          ->send();
        $action->cancel();
        return;
      }
    }
  })
  ->requiresConfirmation()
  ->action(function ($action, $livewire) use ($orderStatusIds){
      // Action logic
  }),

But the before hook does not trigger before the confirmation modal is opened. Am I doing something wrong? Or is there simply no lifecycle hook that triggers before the action modal is opened?
Was this page helpful?