Action->form() not getting filled when reusing form

Hello, Having a Action on a view page. I want to reuse the form from InvoiceResource as i did, but i want to force fill it with data from the $record, but it doesnt get filled. No errors, just doesnt work; Any ideas on how to handle this?
<?php

namespace App\Filament\Resources\OrderResource\Pages;

use App\Filament\Resources\InvoiceResource;
use App\Filament\Resources\OrderResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewOrder extends ViewRecord
{
protected static string $resource = OrderResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ActionGroup::make([
Actions\Action::make('generateInvoice')
->icon('heroicon-o-clipboard-document-list')
->form(fn($record, $form) => InvoiceResource::form($form))
->formData([
'order_id' => $this->record->id,
'receiver_name' => $this->record->names,
'receiver_phone' => $this->record->phone,
'receiver_email' => $this->record->email,
'total' => $this->record->total,
])
->color('gray'),

]) ->button()->color('gray') ->label('Invoice'),
];
}
}
<?php

namespace App\Filament\Resources\OrderResource\Pages;

use App\Filament\Resources\InvoiceResource;
use App\Filament\Resources\OrderResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewOrder extends ViewRecord
{
protected static string $resource = OrderResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ActionGroup::make([
Actions\Action::make('generateInvoice')
->icon('heroicon-o-clipboard-document-list')
->form(fn($record, $form) => InvoiceResource::form($form))
->formData([
'order_id' => $this->record->id,
'receiver_name' => $this->record->names,
'receiver_phone' => $this->record->phone,
'receiver_email' => $this->record->email,
'total' => $this->record->total,
])
->color('gray'),

]) ->button()->color('gray') ->label('Invoice'),
];
}
}
3 Replies
Matthew
Matthew2mo ago
->fillform()
Dimitar Papazov DEV
For some reason when I tried it yesterday it didnt work, now it does; Thanks a lot! Also the action form submit in the modal doesnt get saved, how to trigger the save, or how to get the action form state and save it manualy if I need to?
Matthew
Matthew2mo ago
Since it is an Action and not EditAction, you've got to tell it what to do using an ->action( #in here goes my save logic) method. You can do it directly in there, with $record->phone = $data->receiver_phone; $record->save() etc, or you can pass $record and $data off to a handler to dela with that logic, which makes for neater code.
Want results from more Discord servers?
Add your server