Delete File Confirmation

Hi - is it possible to have a confirmation before removing a file that has been uploaded. I can hide the delete button completely by calling ->deletable(false). However, I have a scenario where users can delete files, but it would be nice to have a confirmation before doing so. Thanks
4 Replies
Azad Furkan ŞAKAR
Did you try? ->deleteAction(fn ($action) => $action->requiresConfirmation())
Adam Holmes
Adam HolmesOP2mo ago
->deleteAction() doesn't seem to be a valid method on the file upload component
Azad Furkan ŞAKAR
Sorry my bad, I just check what can i do if i have this case. I did this for single FileUpload quickly;
Forms\Components\FileUpload::make('file')
->label('File')
->deletable(false)
->hintAction(function () {
return Forms\Components\Actions\Action::make('delete')
->label('Remove File')
->icon('heroicon-o-trash')
->color('danger')
->requiresConfirmation()
->action(function (Forms\Components\FileUpload $component) {
$file = $component->getUploadedFiles();
$firstFileKey = array_key_first($file);
$component->deleteUploadedFile($firstFileKey);
});
}),
Forms\Components\FileUpload::make('file')
->label('File')
->deletable(false)
->hintAction(function () {
return Forms\Components\Actions\Action::make('delete')
->label('Remove File')
->icon('heroicon-o-trash')
->color('danger')
->requiresConfirmation()
->action(function (Forms\Components\FileUpload $component) {
$file = $component->getUploadedFiles();
$firstFileKey = array_key_first($file);
$component->deleteUploadedFile($firstFileKey);
});
}),
Need more practice for multiple files
Adam Holmes
Adam HolmesOP2w ago
Yes whilst this works for individual files, it's not great for multiple files. I will update if I find a better solution

Did you find this page helpful?