Save form from a header action

Is it possible to save a form from a header action (or before a header action?

Let's say I have the following header actions in an edit form

protected function getHeaderActions(): array {
  return [
    Action::make('print'),
    Action::make('duplicate'),
  ]
}

Is there a way to submit the form before any of those actions is executed? Or somehow submit it inside the button action itself?

I tried this but it doesn't work
Action::make('test')
    ->requiresConfirmation()
    ->action(fn (array $data) => dd($data)), // Data is empty


Or if there's a way to detect if a form has been changed and then ask for a confirmation to save before proceeding? Any ideas are welcome.
Solution
Oh okay, you can do something like this:

Action::make('doSomething')
  ->action(function($record, $data) {
    $this->save();
    // ... do something else in the action
  )
Was this page helpful?