Create & create another - reuse fields

When clicking the "Create & create another" button is there a way to reuse some of the input fields? (Have some chosen inputs default to the previous value that was just saved) I have a massive number of fields and many of them could benefit by retaining the same info.
7 Replies
Patrick Boivin
Maybe there's a better option, but if you extend CreateAction in your project, you could customize the behavior around the call to $form->fill() : https://github.com/filamentphp/filament/blob/2.x/packages/admin/src/Pages/Actions/CreateAction.php#L61
bionary
bionaryOP2y ago
Forgive my naiveté but how does one extend CreateAction? It's a core class. I don't see anything in the docs. thanks
Patrick Boivin
No worries! I think there are a few ways to do it but I would probably create a class in my project, something like App\Filament\Pages\Actions\CreateAction
// ...

class CreateAction extends Filament\Pages\Actions\CreateAction
{
protected function setUp(): void
{
parent::setUp();

// your custom setup here
}
}
// ...

class CreateAction extends Filament\Pages\Actions\CreateAction
{
protected function setUp(): void
{
parent::setUp();

// your custom setup here
}
}
bionary
bionaryOP2y ago
Okay I'll try this
Patrick Boivin
Oh wow, yes. I think my solution would only work for a Simple resource (create in modal)...
bionary
bionaryOP2y ago
Cool, got it working. For future travelers: In my Create Page
public function createAnother(): void
{
session()->flash('dataFill', $this->data);
parent::createAnother();
}
public function createAnother(): void
{
session()->flash('dataFill', $this->data);
parent::createAnother();
}
In my form (resource)
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('company')->disabled(fn($context)=>$context=='edit')
->default(fn() => session()->has('dataFill') ? session()->get('dataFill')['company'] : null),
...
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('company')->disabled(fn($context)=>$context=='edit')
->default(fn() => session()->has('dataFill') ? session()->get('dataFill')['company'] : null),
...
Is there any fix for the pre-filled image when using "Create another". I saw some chatter way. back near v.1 that it was fixed...but it doesn't look fixed. When I use "create another" button (v2) the image with fileupload is still there when it should not be.
Want results from more Discord servers?
Add your server