F
Filament10mo ago
gizmojo

How to hook into 'create another' action

Trying to pre-fill the form when you click 'create another' action. It's within a relation manager's table CreateAction. If I overwrite the footer actions when calling makeModalSubmitAction it's returning a StaticAction without access to the form.
5 Replies
Matthew
Matthew10mo ago
Hello, I think you can do something like
CreateAction::make()
->mountUsing(
function (Post $record, Form $form, array $arguments) {
$form->fill([
// ...
]);
}
)
CreateAction::make()
->mountUsing(
function (Post $record, Form $form, array $arguments) {
$form->fill([
// ...
]);
}
)
gizmojo
gizmojoOP10mo ago
Cheers tried that but it's only called on the initial form, not when you call 'Create another'. It's this logic where there doesn't appear to be a way of calling it
No description
Matthew
Matthew10mo ago
Ok wait. I have a solution
Pasteko
Pasteko10mo ago
I'm in the same boat, have you found a way to do this?
gizmojo
gizmojoOP10mo ago
Yeah kinda using afterStateHydrated/Set on a component within the form (credit to @oddvalue for coming up with this work around)
public function form(Form $form): Form
{
return $form
->schema([
Grid::make()
// Instead of filing the form so that it works with 'create another'
->afterStateHydrated(function (TicketsRelationManager $livewire, Set $set, ?Model $record): void {
if ($record?->id) {
return;
}

$data = self::getDefaultFormData($livewire);

foreach ($data as $key => $value) {
$set($key, $value);
}
})
public function form(Form $form): Form
{
return $form
->schema([
Grid::make()
// Instead of filing the form so that it works with 'create another'
->afterStateHydrated(function (TicketsRelationManager $livewire, Set $set, ?Model $record): void {
if ($record?->id) {
return;
}

$data = self::getDefaultFormData($livewire);

foreach ($data as $key => $value) {
$set($key, $value);
}
})
Want results from more Discord servers?
Add your server