-
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. You could use |
||
detail: event.target | ||
}); | ||
document.dispatchEvent(buttonEvent); | ||
|
||
// 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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
document.body.style.marginBottom = null; | ||
document.body.style.marginTop = null; | ||
}, false); | ||
|
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.