Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirmation before removing uploaded Attachments #2010

Open
ajaxray opened this issue Dec 18, 2021 · 1 comment
Open

Confirmation before removing uploaded Attachments #2010

ajaxray opened this issue Dec 18, 2021 · 1 comment
Assignees

Comments

@ajaxray
Copy link

ajaxray commented Dec 18, 2021

Is your feature request related to a problem? Please describe.

The upload field shows a preview of uploaded files. Also shows an (x) button to remove individual files!
Also the similar preview thumbs are displayed for already uploaded Attachments.
CleanShot 2021-12-19 at 04 21 52@2x

Now the problem is, if I click on the delete icon (x) of a thumb, it removes immediately.
If we could display a confirmation before deleting an uploaded image, that would be great!

Describe the solution you'd like
After clicking on the (x) icons, the system will ask for confirmation like "Are you sure to delete this file?"
Also the message can be configurable, like:

Upload::make('upload')
    ->maxFileSize(1024)
    ->deleteConfirmation("Are you sure to delete this product image?")
;

Describe alternatives you've considered
I'm stuck at this point 😓. Tried invoking dropzone confirmation by setting dictRemoveFileConfirmation, but it didn't work.

@ajaxray
Copy link
Author

ajaxray commented Dec 19, 2021

Hi @tabuna ,
Just to let you know, I have come up with an old-school hack (that I am not liking at all 😔).

Using jQuery, just hiding the remove button and adding a new button in place of that.
Onclick, removing the file with a confirmation.

$(document).ready(function() {

    $('.dz-preview .btn-remove').hide();
    $('.dz-preview').not('.dz-message')
        .append('<a href="javascript:;" class="btn-remove with-confirm" draggable="false">x</a>');
    $('.dz-preview .with-confirm').click(function (e) {
        e.stopPropagation();
        if (window.confirm('Are you sure to delete this file?')) {
            var fileId =  $(this).parent().data('file-id');
            var fileObj = Dropzone.instances[0].files.find(function(f){ return f.id == fileId; });
            console.log('Removing:', fileObj);
            Dropzone.instances[0].removeFile(fileObj);
        }
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants