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

Add an event when a form button is clicked #79

Merged
merged 3 commits into from
Nov 17, 2020

Conversation

maartenvanasperen
Copy link
Contributor

No description provided.

@maartenvanasperen maartenvanasperen requested a review from a team November 16, 2020 14:32
@@ -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
Copy link
Contributor

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.

Copy link
Contributor Author

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)

@maartenvanasperen maartenvanasperen force-pushed the feature/reload-page-after-form-click branch from 1d99371 to 12d78f5 Compare November 17, 2020 08:01
@@ -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", {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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", {
Copy link
Contributor

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.

@maartenvanasperen maartenvanasperen changed the title Refresh page on cookieConsent form button click Add an event when a form button is Nov 17, 2020
@maartenvanasperen maartenvanasperen changed the title Add an event when a form button is Add an event when a form button is clicked Nov 17, 2020
@maartenvanasperen maartenvanasperen merged commit 7643950 into master Nov 17, 2020
@maartenvanasperen maartenvanasperen deleted the feature/reload-page-after-form-click branch November 17, 2020 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants