Infolist Action `->createAnother()` doesn't exist

We want to be able to reproduce the ->createAnother() functionality which exists on a Filament\Actions\CreateAction component but Infolists only accept instances of Filament\Infolists\Components\Actions\Action which doesn't have the ->createAnother() option. I have thought about creating our own Action in our codebase, which extends the CreateAction class (to inherit the ->createAnother() function), but using this in an Infolist instance would also fail to satisfy the requirement for it to be an instance of Filament\Infolists\Components\Actions\Action. How can we go about doing this? 🤔
Solution:
try this ```php ->action(function (array $data, Action $action, array $arguments, Form $form) { ...
Jump to solution
7 Replies
Adapt.Patrick
Adapt.PatrickOP6mo ago
Bumping this - any chance anybody can help? 🙏
LeandroFerreira
LeandroFerreira6mo ago
Are you using a page or modal in your resource to create records?
Adapt.Patrick
Adapt.PatrickOP6mo ago
Not sure I quite understand your question @Leandro Ferreira but I'll try and answer it... I have a ProjectResource which uses the infolist() method to control what is rendered to the /view screen. That infolist is then broken down into multiple infolist Sections which use headerActions(). Example below:
public static function infolist(Infolist $infolist): Infolist
{
return $infolist->schema([
Group::make()
->schema([
self::infolistQuoteGroups(),
// ...
])
->columnSpan(1),
Group::make()
->schema([
// ...
])
->columnSpan(1),
])->columns(2);
}

// ...

private static function infolistQuoteGroups(): InfoSection
{
return InfoSection::make('Quote Groups')
->schema([
// ...
])
->headerActions([
// This is the action that I would like to utilise the createAnother() method on...
Action::make('createQuoteGroup')
->label('Add Quote Group')
->form([
TextInput::make('name')
->required(),
])
->modalFooterActionsAlignment('end')
->modalWidth('xl')
->mutateFormDataUsing(function ($data, $record) {
// ...
})
->action(function ($data) {
// ...
})
]);
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist->schema([
Group::make()
->schema([
self::infolistQuoteGroups(),
// ...
])
->columnSpan(1),
Group::make()
->schema([
// ...
])
->columnSpan(1),
])->columns(2);
}

// ...

private static function infolistQuoteGroups(): InfoSection
{
return InfoSection::make('Quote Groups')
->schema([
// ...
])
->headerActions([
// This is the action that I would like to utilise the createAnother() method on...
Action::make('createQuoteGroup')
->label('Add Quote Group')
->form([
TextInput::make('name')
->required(),
])
->modalFooterActionsAlignment('end')
->modalWidth('xl')
->mutateFormDataUsing(function ($data, $record) {
// ...
})
->action(function ($data) {
// ...
})
]);
}
Solution
LeandroFerreira
LeandroFerreira6mo ago
try this
->action(function (array $data, Action $action, array $arguments, Form $form) {

if ($arguments['another'] ?? false) {

//do something

$form->fill();
$action->halt();

return;
}

//do something
})
->extraModalFooterActions(fn (Action $action) => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
])
->action(function (array $data, Action $action, array $arguments, Form $form) {

if ($arguments['another'] ?? false) {

//do something

$form->fill();
$action->halt();

return;
}

//do something
})
->extraModalFooterActions(fn (Action $action) => [
$action->makeModalSubmitAction('createAnother', arguments: ['another' => true])
])
Adapt.Patrick
Adapt.PatrickOP6mo ago
Thanks! I'll give this a go. You legend, @Leandro Ferreira. This worked like a charm! 🙌 Thank you so much for your support. 🔥
Adapt.Patrick
Adapt.PatrickOP6mo ago
While I've got you, @Leandro Ferreira, do you know why section headerActions can't be made to accept some of the default actions (such as CreateAction) and only accept Filament\Infolists\Components\Actions\Action instead?
LeandroFerreira
LeandroFerreira6mo ago
maybe Dan has plans to combine all Action classes into one, but not sure
Want results from more Discord servers?
Add your server