Replicate action: load form instead of save

I was searching for a way to add Clone table action, and came across Replicate action. The only difference between what I want and what this action offers is that, instead of saving the record directly, I want it to be loaded in the form instead, to be saved as a new record when Save button is clicked. Is there a way to do this with Replicate action, or is there some other action to achieve this? I'm looking for a Save As action to be precise.
Solution:
Managed via the following code: ```php Tables\Actions\CreateAction::make('Duplicate') ->label('Duplicate') ->icon('heroicon-o-document-duplicate')...
Jump to solution
2 Replies
Solution
Gandalf
Gandalf7mo ago
Managed via the following code:
Tables\Actions\CreateAction::make('Duplicate')
->label('Duplicate')
->icon('heroicon-o-document-duplicate')
->form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
->fillForm(fn ($record) => $record->toArray()),
Tables\Actions\CreateAction::make('Duplicate')
->label('Duplicate')
->icon('heroicon-o-document-duplicate')
->form(fn (Form $form) => static::form($form->model(static::$model))->columns(2))
->fillForm(fn ($record) => $record->toArray()),
mathieutu
mathieutu2mo ago
Actually, you can do that directly with the ReplicateAction:
Tables\Actions\ReplicateAction::make()->form(fn (Form $form) => static::form($form)->columns(2))
Tables\Actions\ReplicateAction::make()->form(fn (Form $form) => static::form($form)->columns(2))
I don't understand why Filament does not provide the form by default. It may be an issue.
Want results from more Discord servers?
Add your server