Is it possible to add actions to a footer or header widget on a view page?

I am working on an approvals package, and I want for the user to be able to perform an approval action(approve, reject, submit etc) at the bottom of the view page. I attempted to do this by adding a footer widget and then adding an action(for example approve). But the action appears to be disabled. I added the same widget to the Edit page, and the button was still disabled. Is this feature possible in filament, if yes, how?
7 Replies
toeknee
toeknee8mo ago
It should be possible, why does it seem disabled?
eightynine
eightynine8mo ago
So far this is my implementation: This is the approval widget
<?php

namespace EightyNine\Approvals\Widgets;

use EightyNine\Approvals\Forms\Actions\SubmitAction;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;

class ApprovalWidget extends Widget implements HasForms, HasActions
{
use InteractsWithForms, InteractsWithActions;

public ?Model $record = null;

protected static bool $isLazy = false;

protected int | string | array $columnSpan = 'full';

protected static string $view = 'filament-approvals::widgets.approval-widget';

public function submitAction(): Action
{
return SubmitAction::make()
->record($this->record);
}
}
<?php

namespace EightyNine\Approvals\Widgets;

use EightyNine\Approvals\Forms\Actions\SubmitAction;
use Filament\Actions\Action;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Filament\Widgets\Widget;
use Illuminate\Database\Eloquent\Model;

class ApprovalWidget extends Widget implements HasForms, HasActions
{
use InteractsWithForms, InteractsWithActions;

public ?Model $record = null;

protected static bool $isLazy = false;

protected int | string | array $columnSpan = 'full';

protected static string $view = 'filament-approvals::widgets.approval-widget';

public function submitAction(): Action
{
return SubmitAction::make()
->record($this->record);
}
}
This is the view file:
<x-filament-widgets::widget>
<x-filament::section>
{{-- Widget content --}}
{{ $this->submitAction }}

</x-filament::section>
</x-filament-widgets::widget>
<x-filament-widgets::widget>
<x-filament::section>
{{-- Widget content --}}
{{ $this->submitAction }}

</x-filament::section>
</x-filament-widgets::widget>
And then I added this the view record on my resource file:
protected function getFooterWidgets(): array
{
return [
ApprovalWidget::class
];
}
protected function getFooterWidgets(): array
{
return [
ApprovalWidget::class
];
}
On the UI, I get the submit button but upon clicking, nothing happens
No description
toeknee
toeknee8mo ago
if you dd($this->record) does it dump the record?
eightynine
eightynine8mo ago
Yes, it shows the record
No description
No description
toeknee
toeknee8mo ago
Is Submit disabled at the button level? If you click it, do you see it in the network logs being clicked?
eightynine
eightynine8mo ago
no, there is no network logs, and it is not disabled at the button level
toeknee
toeknee8mo ago
Source dive into the class extension and what it extends.