Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted over 2 years ago

Carpet of Fury

Mahdi Aljaza'iri•250
@MahdiAljazairi
A solution to the Base Apparel coming soon page challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


See README.

method="dialog"??

I put a method of "dialog" on the form because otherwise the page would reload when the form is submitted as I didn't provide an actual action URL. This is for demo purpose only. In production, this should be switched to "post" instead.

About the Invalid State

When you look at the CSS, you'll notice that I used a [data-invalid] attribute, with some help of Javascript, on the input element to indicate whether it's invalid or not instead of simply an :invalid pseudo-class. This is because if I used the pseudo-class, the input would show invalid state styles immediately when the page loads -- since, of course, the input is required. Then, those styles would disappear the moment you type in a valid email address.

We don't want that. Because, as per the terms of the challenge, form validation should take place only if there was an attempt to submit the form. And this is exactly what I did. I put an onclick to call a function named checkInput() on my button, as it's the form's only submit button. This means it would still work even if the form was submitted using the Enter key. The form would behave as if its submit button has been clicked.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Mahdi Aljaza'iri'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

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License