F
Filament15mo ago
Rama

Form actions must be an instance of Filament\Actions\Action, or Filament\Actions\ActionGroup.

hello all good evening, I need help why when I want to create pages an error appears like this
No description
14 Replies
toeknee
toeknee15mo ago
you need to provide your code of the resource.
InSeriousNeedOfHelp
this code:
Actions::make([
Action::make('star')
->icon('heroicon-m-star')
->requiresConfirmation()
->action(function (Star $star) {
$star();
}),
Action::make('resetStars')
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->action(function (ResetStars $resetStars) {
$resetStars();
}),
])
Actions::make([
Action::make('star')
->icon('heroicon-m-star')
->requiresConfirmation()
->action(function (Star $star) {
$star();
}),
Action::make('resetStars')
->icon('heroicon-m-x-mark')
->color('danger')
->requiresConfirmation()
->action(function (ResetStars $resetStars) {
$resetStars();
}),
])
Triggers that error. This is the same as the code at this page in the guide: https://filamentphp.com/docs/3.x/forms/actions#adding-anonymous-actions-to-a-form-without-attaching-them-to-a-component
alexanderkroneis
alexanderkroneis15mo ago
Where did you put that code? I assume that your IDE is not using
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
Dennis Koch
Dennis Koch15mo ago
Please show the full code
InSeriousNeedOfHelp
I am actually using both One could argue that the code I'm using, being the same of the startup guide I previously linked, does not matter, bu anyways, here it goes: https://gist.github.com/FraSaid/e1d10d38e277dec17b0887fcf563242a
Dennis Koch
Dennis Koch15mo ago
The startup guide might be wrong then. Did you try the suggested classes instead? Your Filament version is up-to-date? Can you share the artisan about section for Filament?
InSeriousNeedOfHelp
I'm on 3.0.6, updated my composer this morning. The proble with using the suggested classes is that the "Actions" component for the form takes as input in it's constructor of type array<Action>, where Action comes from use Filament\Forms\Components\Actions\Action; So I cannot mix and match the suggested classes, as one requires the I would assume, correct one: Filament\Forms\Components\Actions\Action but the mount function breaks if the object is not either a Filament\Actions\Action, or Filament\Actions\ActionGroup
Dennis Koch
Dennis Koch15mo ago
I think the issue it, that you are using the same class for getHeaderActions(). You need to use aliases so you can use a different class there
InSeriousNeedOfHelp
I get it, the Header uses Filament/Actions/Action, and that was not imported or aliased Thanks a lot Dennis, I wasn't really thinking about the possibility of both having the same name
Dennis Koch
Dennis Koch15mo ago
There are a lot of different Action classes which unfortunately leads to clashes in some cases.
alexanderkroneis
alexanderkroneis15mo ago
I noticed that yesterday when I extracted my actions into classes. Could that somehow be resolved? I'd be willing to support a PR.
Dennis Koch
Dennis Koch15mo ago
We'd need to prefix them all probably. But they are already prefixed by the namespace. That's what aliases are for. What's your proposed solution?
alexanderkroneis
alexanderkroneis15mo ago
I implemented every action twice. One of the list item, another of the view page. It's the same logic and I'd like to reduce them to one action since it's duplicated code. I played around a little bit yesterday, but did not find a solution to reduce them to one action
Dennis Koch
Dennis Koch15mo ago
Ah, right. Not really sure if there's is a good solution. There are different actions for a reason and not everything is supported everywhere. You could reuse your code by extending the base action and then extending the other actions from that. One more class, but no duplicated ode.
Want results from more Discord servers?
Add your server