F
Filament10mo ago
johny7

How to call the second action after submitting the first action-form?

Moin together. I have on an edit page of a resource 4 header-actions with modal forms. I want to offer the possibility to jump directly to the modal form of the next header-action after submitting one of these forms. The wizard steps are not enough for me, because I don't see (at least not yet) a possibility to save the data already when changing the step. I can call ->extraModalFooterActions() for example ->makeModalSubmitAction() to save the form. But how do I get it to call the next modal directly afterwards without defining the whole form as sub-modal again? Finally, I have defined the 4 header-actions with their forms on the page. I have tried ->extraAttributes(['wire:target' => '']) and various functions, so far without success. Thanks in advance for the suggestions.
4 Replies
johny7
johny79mo ago
Thank you very much, I'll try this. This works very fine! Just had to use Action::make() instead of $action->makeModalSubmitAction()
cheesegrits
cheesegrits9mo ago
@johny7 can you provide an example of your working code, help the next person who stumbles across this?
johny7
johny79mo ago
Of course, here you are:
<?php

namespace App\Filament\Resources\ProbeResource\Pages;

use App\Filament\Resources\ProbeResource;
use Filament\Resources\Pages\EditRecord;
use Filament\Actions;

class EditProbe extends EditRecord
{
protected static string $resource = ProbeResource::class;

protected function getHeaderActions(): array
{
return [
Actions\Action::make("awl")
->form([
# Form Data here
])
->extraModalFooterActions(function (Actions\Action $action) {
return [
$action->make('save')
->action(function () {
$data = $this->mountedActionsData[0]['anwesenheiten']; // Get Form Data
Anwesenheit::upsert($data, ['id']); // Save Form Data
})
->close(true),
Actions\Action::make('saveNjump')
->action(function () {
$data = $this->mountedActionsData[0]['anwesenheiten']; // Get Form Data
Anwesenheit::upsert($data, ['id']); // Save Form Data
$this->replaceMountedAction("targetaction", []); // jump to next Action
})
];
}),
// Other Header Actions
];
}
}
<?php

namespace App\Filament\Resources\ProbeResource\Pages;

use App\Filament\Resources\ProbeResource;
use Filament\Resources\Pages\EditRecord;
use Filament\Actions;

class EditProbe extends EditRecord
{
protected static string $resource = ProbeResource::class;

protected function getHeaderActions(): array
{
return [
Actions\Action::make("awl")
->form([
# Form Data here
])
->extraModalFooterActions(function (Actions\Action $action) {
return [
$action->make('save')
->action(function () {
$data = $this->mountedActionsData[0]['anwesenheiten']; // Get Form Data
Anwesenheit::upsert($data, ['id']); // Save Form Data
})
->close(true),
Actions\Action::make('saveNjump')
->action(function () {
$data = $this->mountedActionsData[0]['anwesenheiten']; // Get Form Data
Anwesenheit::upsert($data, ['id']); // Save Form Data
$this->replaceMountedAction("targetaction", []); // jump to next Action
})
];
}),
// Other Header Actions
];
}
}