How do I use actions on a ViewRecord page?

Hi, I've created a custom ViewRecord view for my resource with a section showing several buttons and actions. I've created an action that should open a modal with a form. The action is rendered correctly but when I click, I see the spinner and nothing happens (0 console or PHP errors). Here my ViewRecord (without all stuffs) and a dump action :
class ViewOrder extends ViewRecord
{
protected static string $resource = OrderResource::class;

protected static string $view = 'filament.resources.order.view-order';



public function generateJobSheet(): Action
{
return Action::make('test')
->form([
Select::make('user_id')
->options(User::all()->pluck('email', 'id')),
])
->action(function (array $data): void {
dd($data);
});
}

public function infolist(Infolist $infolist): Infolist
{
return $infolist->schema([...]);
}

protected function getHeaderActions(): array
{
return [...];
}
}
class ViewOrder extends ViewRecord
{
protected static string $resource = OrderResource::class;

protected static string $view = 'filament.resources.order.view-order';



public function generateJobSheet(): Action
{
return Action::make('test')
->form([
Select::make('user_id')
->options(User::all()->pluck('email', 'id')),
])
->action(function (array $data): void {
dd($data);
});
}

public function infolist(Infolist $infolist): Infolist
{
return $infolist->schema([...]);
}

protected function getHeaderActions(): array
{
return [...];
}
}
And my view attached) (I copied and pasted the default view and added my part) I also tried to follow that guide : https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component with adding this but nothing changed :
class ViewOrder extends ViewRecord implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

protected static string $resource = OrderResource::class;

protected static string $view = 'filament.resources.order.view-order';

public function getFormStatePath(): ?string
{
return 'data';
}
class ViewOrder extends ViewRecord implements HasActions, HasForms
{
use InteractsWithActions;
use InteractsWithForms;

protected static string $resource = OrderResource::class;

protected static string $view = 'filament.resources.order.view-order';

public function getFormStatePath(): ?string
{
return 'data';
}
I thought it might be coming from the Section, so I removed the button to put it lower down, but the same thing happened... Can somebody help me ? Thanks 🙂
Solution:
Do you really need to overwrite the view? Header Actions don't fit for your use case? Regarding the action: The action name and the function must match. In your case the function should be named testAction()...
Jump to solution
7 Replies
Nijholt
Nijholt2d ago
Try using $arguments:
->action(function (array $arguments): void {
dd($arguments);
});
->action(function (array $arguments): void {
dd($arguments);
});
Alexandre
AlexandreOP2d ago
Hi, thanks for your answer but that didn't change anything 😥
Nijholt
Nijholt2d ago
Ah shoot! It did the trick for me: https://discord.com/channels/883083792112300104/1342447016567115827 Good luck!
Solution
Dennis Koch
Dennis Koch2d ago
Do you really need to overwrite the view? Header Actions don't fit for your use case? Regarding the action: The action name and the function must match. In your case the function should be named testAction()
Alexandre
AlexandreOP2d ago
Yes, it's for a client and the process is quite... Special. They want to force their users to go through the details before seeing the action buttons, so I've put this in a section in my view below the InfoList 🙂 And... I was just about to reply, because I've found the solution and it's what you've just written. I'll have to pay more attention to the documentation, especially the comments in the code 😅 Cf. https://filamentphp.com/docs/3.x/actions/adding-an-action-to-a-livewire-component#adding-the-action Thank you very much for your help and your time 🙏
No description
Dennis Koch
Dennis Koch2d ago
Not just the code 😅
The method must share the exact same name as the action, or the name followed by Action:
Alexandre
AlexandreOP2d ago
Oh mamma mia, I'm an idiot but it's almost the weekend 😂. I'm going to make the most of it by picking daisies in the fields and getting some fresh air. 😂 Sorry 😅

Did you find this page helpful?