-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add an event when a form button is clicked #79
Add an event when a form button is clicked #79
Conversation
@@ -37,7 +37,8 @@ document.addEventListener("DOMContentLoaded", function() { | |||
xhr.open('POST', cookieConsentForm.action); | |||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |||
xhr.send(serializeForm(cookieConsentForm, event.target)); | |||
// Clear all styles from body to prevent the white margin at the end of the page | |||
location.reload(); | |||
// Clear all styles from body to prevent the white margin at the end of the page |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this will prompt the user to re-submit any forms (if they have sent any POST data recently), which is not an optimal UX. I think window.location.href = window.location.href;
should work. Also, the document styles below will become redundant because they will not happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion, I can use that in the event listener. For now it creates a custom event, instead of a forced refresh after a button click, so everyone can use another functionality if required. (see new commit)
1d99371
to
12d78f5
Compare
12d78f5
to
587abfe
Compare
@@ -37,7 +37,13 @@ document.addEventListener("DOMContentLoaded", function() { | |||
xhr.open('POST', cookieConsentForm.action); | |||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |||
xhr.send(serializeForm(cookieConsentForm, event.target)); | |||
// Clear all styles from body to prevent the white margin at the end of the page | |||
|
|||
let buttonEvent = new CustomEvent("cookie-consent-form-button-click", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let buttonEvent = new CustomEvent("cookie-consent-form-button-click", { | |
let buttonEvent = new CustomEvent('cookie-consent-form-button-click', { |
@@ -37,7 +37,13 @@ document.addEventListener("DOMContentLoaded", function() { | |||
xhr.open('POST', cookieConsentForm.action); | |||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); | |||
xhr.send(serializeForm(cookieConsentForm, event.target)); | |||
// Clear all styles from body to prevent the white margin at the end of the page | |||
|
|||
let buttonEvent = new CustomEvent("cookie-consent-form-button-click", { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use var
instead of let
to keep it consistent with the other variables.
No description provided.