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

confirmDelete issue #162

Closed
esglobal opened this issue Jul 23, 2023 · 3 comments
Closed

confirmDelete issue #162

esglobal opened this issue Jul 23, 2023 · 3 comments

Comments

@esglobal
Copy link

esglobal commented Jul 23, 2023

  • Package Version: 7.0.0
  • Laravel Version: 10.15.0

Description: In a certain scenario, a click on the button doesn't trigger the confirmation dialog. If we replace Delete with let's say an icon, it stops working and just redirects the user to route('users.destroy', $user->id)

Steps To Reproduce: Just replace

<a href="{{ route('users.destroy', $user->id) }}" class="btn btn-danger" data-confirm-delete="true">Delete</a>

with

<a href="{{ route('users.destroy', $user->id) }}" class="btn btn-danger" data-confirm-delete="true"><i class="fa fa-fw fa-times"></i></a>

@esglobal
Copy link
Author

Update: it works if you use the icon AND a text but doesn't work if we use just an icon the the a tag.

@thobiasvicente
Copy link

thobiasvicente commented Jul 26, 2023

It seems that there is a bug when clicking an icon; the click action triggers on the icon itself rather than the <a> tag. It's a bit puzzling, but I found a workaround that worked. Here's what I did:

  1. Add data-confirm-delete="true" to the icon:
<a href="{{ route('users.destroy', $user->id) }}" class="btn btn-danger" data-confirm-delete="true">
    <i data-confirm-delete="true" class="fa fa-fw fa-times"></i>
</a>
  1. To fix the issue, you need to publish the package using php artisan sweetalert:publish. Then, go to resources/views/vendor/sweetalert/alert.blade.php and change line 21 as follows:

Before:

form.action = event.target.href;

After:

form.action = event.target.closest('a').href;

This change is necessary because when you click on the icon, the code searches for the href data, but it's on the <a> tag.

After making this change, it should work. While there might be a better solution, at least this workaround does the job.

@esglobal
Copy link
Author

It works fine. Thanks @thobiasvicente

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

No branches or pull requests

2 participants