Change delete action type and position in edit form.

Hi there, I need to change the delete action type to link and want to show it below the last form section on the edit form. I have attached the snapshot of what I need. I have got some what close to it but Delete action is not working.
Forms\Components\Section::make('Status')
->schema([
Forms\Components\Toggle::make('is_active')
->label('Status')
->default(true),

Forms\Components\TextInput::make('updated_at')
->label('Last Updated')
->disabled(),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->color('danger')
->action('delete'),
])
]),
])
->columnSpan(['lg' => 1]),
Forms\Components\Section::make('Status')
->schema([
Forms\Components\Toggle::make('is_active')
->label('Status')
->default(true),

Forms\Components\TextInput::make('updated_at')
->label('Last Updated')
->disabled(),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->color('danger')
->action('delete'),
])
]),
])
->columnSpan(['lg' => 1]),
Can someone help me with this? Thanks in advance.
No description
Solution:
```php Forms\Components\Actions::make([ Forms\Components\Actions\Action::make('delete') ->requiresConfirmation()...
Jump to solution
13 Replies
toeknee
toeknee15mo ago
You need to make the action a functionable action:
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->color('danger')
->action(fn($record) => $record->delete()),
])
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->color('danger')
->action(fn($record) => $record->delete()),
])
azimBelim
azimBelimOP15mo ago
and how can i hide it on create form?
Solution
toeknee
toeknee15mo ago
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->visible(fn($context) => $context === 'edit')
->color('danger')
->action(fn($record) => $record->delete()),
])
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->visible(fn($context) => $context === 'edit')
->color('danger')
->action(fn($record) => $record->delete()),
])
azimBelim
azimBelimOP15mo ago
Thank you again that worked for me. on delete it says Can't set model as property if it hasn't been persisted yet
toeknee
toeknee15mo ago
IF you try it with just 'delete' instead of my closure, does it work?
azimBelim
azimBelimOP15mo ago
no it just opened confirmation pop up and on confirming it closes the pop up
toeknee
toeknee15mo ago
Have a look at how the edit page adds the delete aciton, it should explain it
azimBelim
azimBelimOP15mo ago
It uses Filament/Actions => DeleteAction for the default delete button. I am unable to use it in Form Actions
azimBelim
azimBelimOP15mo ago
this is what i get
No description
toeknee
toeknee15mo ago
That's because it's not part of the component, can you provide the code you are using If it's 'delete' within the action, That would make sense. You probably need to adjust the action to get an id etc for the record to delete. I maybe use $livewire instead and $livewire->parent ?
azimBelim
azimBelimOP15mo ago
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->visible(fn($context) => $context === 'edit')
->color('danger')
->action('delete'),
])
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('delete')
->requiresConfirmation()
->link()
->visible(fn($context) => $context === 'edit')
->color('danger')
->action('delete'),
])
this is the code I am using which throws above exception.
toeknee
toeknee15mo ago
That likely will because you don't have a default function on the component you are calling ti from, that's why the action should ideally be an actual default action. i.e. ->action(fn($data, $record) => dd($record)) should dump die the record with all the info, so you should be able to use standard model practices to delete the record.
azimBelim
azimBelimOP15mo ago
Thanks but I just used the default action as link and placed it in the bottom of the form.
Want results from more Discord servers?
Add your server