Design comparison
Solution retrospective
πΎ Hello, Frontend Mentor coding community.
This is my solution for the Base-Apparel-coming-soon-page challenge.
Problem: Well yes I know you seen the JS fileπ. It looks horrible right. if you could give me any resources to help me understand form validation that will be great.
Ill be happy to hear any feedback and advice!
Community feedback
- @EileenpkPosted over 1 year ago
Hi Godstime! your project looks good.
Forms were hard for me too when I started, and validation can get messy. Here are a few things I see that might help.
In your HTML:
- Add an aria-label to the email input for accessibility
<input type="email" name="email" id="email" placeholder="Email Address" aria-label="Email Address">
In your JS:
- Change the event listener to use input event instead of click, this will fire every time the input field changes
- Add or remove classes instead of manipulating them
- Check for an empty input before checking for a pattern match, currently if I try to submit the form with an empty email input, no error is shown
email.addEventListener('input', validateEmail); function validateEmail() { if (email.value.trim() === '') { paragraph.innerHTML = 'Please provide an email'; email.classList.remove('bg-form'); error.src = ''; } else if (!email.value.match(patterns)) { paragraph.innerHTML = 'Please provide a valid email'; email.classList.add('bg-form'); error.src = '../images/icon-error.svg'; } else { paragraph.innerHTML = 'Please submit the email'; email.classList.remove('bg-form'); error.src = ''; } }
Hope you found this helpful!
- Let's connect on LinkedIn! - @Eileenpk
Marked as helpful1@iceberg61Posted over 1 year ago@Eileenpk You literally just explain what i have been busting my ass off in literally 2 minutesππππ. Thanks alot. it Was very helpful. Much love from Godstime
0 - @0xabdulkhaliqPosted over 1 year ago
Hello there π. Congratulations on successfully completing the challenge! π
- I have other recommendations regarding your code that I believe will be of great interest to you.
JAVASCRIPT π‘:
- The way you declared variables are need to be well structured and organized
- Take a look at the following example code which describes an efficient way of declaring variables
const firstName = "Your"; const lastName = "Name"; const emailAddress = "[email protected]"; const password = "supersecret";
- instead try this,
const firstName = "Your", lastName = "Name", emailAddress = "[email protected]" β’β’β’ β’β’β’ // n number of declarations password = "supersecret"; // make sure to add a semicolon at end of last declaration
- This single line declaration with separated commas will helps you to have a better structured code and improves readability though
.
I hope you find this helpful π Above all, the solution you submitted is great !
Happy coding!
Marked as helpful0@iceberg61Posted over 1 year ago@0xAbdulKhalid i WIll definitely start structuring my variables THanks alot for the feedback
0
Please log in to post a comment
Log in with GitHubJoin 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