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

Fix handler not working on <button> elements and breaking after first… #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

feliperaul
Copy link

… click

2 changes:

  1. The handler was filter only a elements with data-confirm-swal attributes. It's very common to use data-confirm attributes in button elements (for instance, on submitting forms, so I removed the a restriction, activating the handler on any element that has data-confirm-swal.

  2. If you have a button that is meant to be clicked more than once, the previous code didn't work. Imagine, for instance, a "delete all" button, that stays fixed in the UI, and when confirmed a partial is updated via ajax .. since the script removed the data-confirm-swal after the first click, from the second click onwards the SweetAlert wouldn't be triggered. This pull request stores the previous data-confirm-swal in a temp variable, clicks the button (so the infinite Swal loop is avoided), and then (and only then) restaures the sweet alert behavior, so it keeps working for other clicks.

… click

2 changes:

1) The handler was filter only `a` elements with `data-confirm-swal` attributes. It's very common to use `data-confirm` attributes in `button` elements (for instance, on submitting forms, so I removed the `a` restriction, activating the handler on any element that has `data-confirm-swal`. 

2) If you have a button that is meant to be clicked more than once, the previous code didn't work. Imagine, for instance, a "delete all" button, that stays fixed in the UI, and when confirmed a partial is updated via ajax .. since the script removed the `data-confirm-swal` after the first click, from the second click onwards the SweetAlert wouldn't be triggered. This pull request stores the previous `data-confirm-swal` in a temp variable, clicks the button (so the infinite Swal loop is avoided), and then (and only then) restaures the sweet alert behavior, so it keeps working for other clicks.
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

Successfully merging this pull request may close these issues.

1 participant