-
Notifications
You must be signed in to change notification settings - Fork 220
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
Javascript data-confirm fires multiple times #284
Comments
Makes sense. Can you please send a PR that moves to a named function? Thank you! |
@josevalim Sure, I will take a look at implementing a solution tomorrow. |
Hi @tomciopp, so I asked around to know if the global is necessary and I was told that Turbolinks do not make it a requirement as long as you load scripts on the head, as advised by Turbolinks. Are you loading Phoenix HTML and friends on the |
Yes, everything is loaded in the |
If you're using something like turbolinks,
phoenix_html
may get loaded multiple times. This leads to a situation where users will have to click the confirm dialog over and over to get the dialog to disappear.Looking at the code and the docs for addEventListener, I believe there should be a simple fix to this problem.
It looks like the root of the problem is the fact that we are using anonymous functions when adding the event listener. If we can ensure that the functions are static when the code runs again the additional event listener will be ignored since it is identical. Since this is based off behavior from rails I think it would be good to borrow/steal their implementation since it should handle these problems out of the box.
https://github.com/rails/rails/tree/master/actionview/app/assets/javascripts
The text was updated successfully, but these errors were encountered: