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
Matthew5mo 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
gizmojo5mo 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
Matthew5mo ago
Ok wait. I have a solution
Pasteko
Pasteko4mo ago
I'm in the same boat, have you found a way to do this?
gizmojo
gizmojo4mo 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);
}
})