Skip to content
Submitted about 2 months ago

🚀 Newsletter Sign-up Form ✨

accessibility, animation, bem, semantic-ui
P
LVL 3
Christian Diaz•225
@chrisdzasc
A solution to the Newsletter sign-up form with success message challenge

Solution retrospective


What are you most proud of, and what would you do differently next time?

I am proud of the JavaScript logic I built for the form's error handling. Instead of just blindly creating a new error message element every time the user clicks submit, I implemented a DOM state check to see if the error already exists. This completely prevents the "spam click" bug and optimizes the browser's memory.

I am also really happy with the custom CSS @keyframes animation I wrote for the success card. Combining opacity and transform: translateY gave the component a premium slide-up entrance that feels much more natural than a sudden layout shift.

What challenges did you encounter, and how did you overcome them?

The "Spam-Click" Error Message Bug

The Challenge: Initially, my JavaScript logic blindly manufactured a brand new <p> element for the error message every single time the user clicked "Submit" with an invalid email. If a user spam-clicked the button, multiple error messages would stack up in the UI before the setTimeout could remove them.

The Solution: I implemented a "Look before you build" DOM state check. Before executing document.createElement, my script uses document.querySelector to check if the error class already exists on the screen. By wrapping the creation logic inside an if (errorAlert = null) statement, the script only build the error message if one isn't already there.

What specific areas of your project would you like help with?

I would love a general code review! Any feedback on my HTML semantics, CSS architecture or JavaScript logic is highly appreciated. Let me know if you see any areas where I could improve or follow better industry best practices!

Code
Loading...

Please log in to post a comment

Log in

Community feedback

No feedback yet. Be the first to give feedback on Christian Diaz’s solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord