-
Notifications
You must be signed in to change notification settings - Fork 150
fix(footer): prevent newsletter form reload, add validation, and stop input expanding on focus #880
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
Conversation
… input expanding on focus Signed-off-by: Pankaj Kumar Bind <pankajbind30@gmail.com>
Signed-off-by: Pankaj Kumar Bind <pankajbind30@gmail.com>
✅ Deploy Preview for bejewelled-pegasus-b0ce81 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
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.
Pull request overview
This PR addresses issue #827 by fixing several UX issues with the newsletter subscription form in the footer. The changes prevent page reloads on form submission, add client-side email validation with user feedback, and improve the input field's focus behavior.
Key Changes:
- Added form submission prevention with
e.preventDefault()to stop page refresh - Implemented client-side email validation with regex pattern and real-time error messaging
- Simplified CSS focus styles to prevent unexpected input expansion while maintaining visual feedback
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| layouts/partials/footer.html | Added form IDs, email input validation, error message display area, and JavaScript event handlers for form submission and validation |
| assets/scss/_footer_project.scss | Removed width/padding changes on input focus, replaced with subtle border transition for better UX |
layouts/partials/footer.html
Outdated
| <div class="row footer-info2 subscribe"> | ||
| <div class="footer-end"> | ||
| <form name="contactform"> | ||
| <form name="contactform" id="newsletter-form"> |
Copilot
AI
Dec 17, 2025
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.
The form lacks an action attribute or backend integration to actually handle newsletter subscriptions. Currently, the form only shows a success message but doesn't submit the email address anywhere. You need to add either a form action URL, integrate with a newsletter service (e.g., Mailchimp, Netlify Forms), or implement an API endpoint to handle the subscription.
layouts/partials/footer.html
Outdated
| <script> | ||
| document.addEventListener('DOMContentLoaded', function() { | ||
| const form = document.getElementById('newsletter-form'); | ||
| const emailInput = document.getElementById('newsletter-email'); | ||
| const messageDiv = document.getElementById('newsletter-message'); | ||
|
|
||
| function showMessage(text, isError) { | ||
| messageDiv.textContent = text; | ||
| messageDiv.style.color = isError ? '#ff6b6b' : '#00d3a9'; | ||
| } | ||
|
|
||
| function clearMessage() { | ||
| messageDiv.textContent = ''; | ||
| } | ||
|
|
||
| if (form) { | ||
| emailInput.addEventListener('input', clearMessage); | ||
|
|
||
| form.addEventListener('submit', function(e) { | ||
| e.preventDefault(); | ||
|
|
||
| const email = emailInput.value.trim(); | ||
|
|
||
| if (!email) { | ||
| showMessage('Please enter your email address', true); | ||
| emailInput.focus(); | ||
| return false; | ||
| } | ||
|
|
||
| const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; | ||
| if (!emailRegex.test(email)) { | ||
| showMessage('Please enter a valid email address', true); | ||
| emailInput.focus(); | ||
| return false; | ||
| } | ||
|
|
||
| showMessage('Thank you for subscribing!', false); | ||
| emailInput.value = ''; | ||
|
|
||
| return false; | ||
| }); | ||
| } | ||
| }); | ||
| </script> |
Copilot
AI
Dec 17, 2025
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.
Consider extracting this JavaScript code into a separate file in assets/js/ (e.g., newsletter-form.js) following the project structure where JavaScript files are kept separate from HTML templates. This improves maintainability and allows for better code organization.
layouts/partials/footer.html
Outdated
| function showMessage(text, isError) { | ||
| messageDiv.textContent = text; | ||
| messageDiv.style.color = isError ? '#ff6b6b' : '#00d3a9'; | ||
| } |
Copilot
AI
Dec 17, 2025
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.
Hardcoded color values in JavaScript should be moved to CSS classes or variables. Define error and success message styles in the SCSS file (e.g., .newsletter-message--error and .newsletter-message--success) and toggle classes instead of directly manipulating inline styles. This keeps styling consistent with the rest of the project and makes theme changes easier.
layouts/partials/footer.html
Outdated
| <input class="footer-input" id="newsletter-email" type="email" placeholder="Email Address" required /> | ||
| <button class="footer-button" title="Subscribe" type="submit">Subscribe</button> | ||
| </div> | ||
| <div id="newsletter-message" style="margin-top: 0.5rem; font-size: 0.9rem; min-height: 1.5rem;"></div> |
Copilot
AI
Dec 17, 2025
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.
Consider adding aria-describedby="newsletter-message" to the email input and aria-live="polite" to the message div to improve accessibility for screen reader users. This will ensure that validation messages are announced to users who rely on assistive technology.
| <input class="footer-input" id="newsletter-email" type="email" placeholder="Email Address" required /> | |
| <button class="footer-button" title="Subscribe" type="submit">Subscribe</button> | |
| </div> | |
| <div id="newsletter-message" style="margin-top: 0.5rem; font-size: 0.9rem; min-height: 1.5rem;"></div> | |
| <input class="footer-input" id="newsletter-email" type="email" placeholder="Email Address" required aria-describedby="newsletter-message" /> | |
| <button class="footer-button" title="Subscribe" type="submit">Subscribe</button> | |
| </div> | |
| <div id="newsletter-message" aria-live="polite" style="margin-top: 0.5rem; font-size: 0.9rem; min-height: 1.5rem;"></div> |
layouts/partials/footer.html
Outdated
| <div style="display: flex; align-items: flex-start; flex-direction: column;"> | ||
| <div style="display: flex; align-items: center;"> | ||
| <input class="footer-input" id="newsletter-email" type="email" placeholder="Email Address" required /> | ||
| <button class="footer-button" title="Subscribe" type="submit">Subscribe</button> | ||
| </div> | ||
| <div id="newsletter-message" style="margin-top: 0.5rem; font-size: 0.9rem; min-height: 1.5rem;"></div> | ||
| </div> |
Copilot
AI
Dec 17, 2025
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.
Inline styles should be moved to the SCSS file for better maintainability and consistency with the rest of the codebase. Create CSS classes in assets/scss/_footer_project.scss for these layout styles (e.g., .newsletter-wrapper, .newsletter-input-container, .newsletter-message).
- Extract inline JavaScript to external file (newsletter.js) - Replace inline styles with CSS classes for better maintainability - Add proper ARIA labels and semantic HTML for accessibility - Add JSDoc comments for better code documentation - Add visually-hidden class for accessible form labels - Use Hugo asset pipeline for JavaScript loading with defer attribute Signed-off-by: Pankaj Kumar Bind <pankajbind30@gmail.com>
8495c0e to
bcb623a
Compare
|
@leecalcote I’ve fixed the issues and made the necessary changes suggested by Copilot. |
Notes for Reviewers
This PR fixes issue #827 and some more issues
Fix: Prevent default form submission to stop page refresh on Subscribe.
Currently, clicking the Subscribe button refreshes the page, which does not align with modern UX standards. Additionally, users do not receive any feedback indicating whether the subscription was successful or failed.
Validation: Add client-side validation (required + regex) and focus on error.
UX: Prevent unexpected input expansion by removing width change on :focus and adding a subtle border transition.
Signed commits