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'),
]
}
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
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: ```php Action::make('doSomething') ->action(function($record, $data) {...
Jump to solution
8 Replies
JibayMcs
JibayMcs2mo ago
Hi ! You can try this:
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
// Custom Save Form Action
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->action('save')
];
}
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
// Custom Save Form Action
Action::make('save')
->label(__('filament-panels::resources/pages/edit-record.form.actions.save.label'))
->action('save')
];
}
ChesterS
ChesterSOP2mo ago
Hey sorry I wasn't clear in my original question. I want to save the form and do something else in the action. An example would be something like
Action::make('doSomething')
->action(function($record, $data) {
$record->update($data);
// ... do something else in the action
)
Action::make('doSomething')
->action(function($record, $data) {
$record->update($data);
// ... do something else in the action
)
Thanks for you suggestion though - I think I might actually need it soon!
Solution
JibayMcs
JibayMcs2mo ago
Oh okay, you can do something like this:
Action::make('doSomething')
->action(function($record, $data) {
$this->save();
// ... do something else in the action
)
Action::make('doSomething')
->action(function($record, $data) {
$this->save();
// ... do something else in the action
)
JibayMcs
JibayMcs2mo ago
(not tested)
ChesterS
ChesterSOP2mo ago
Oh shit, this actually works haha
JibayMcs
JibayMcs2mo ago
😄
ChesterS
ChesterSOP2mo ago
TY ❤️
JibayMcs
JibayMcs2mo ago
De nada !
Want results from more Discord servers?
Add your server