finished javascript of intro challenge

This commit is contained in:
Robert McGovern 2022-09-28 21:06:27 +01:00
parent 2cc18325ae
commit 86a559963e
9 changed files with 249 additions and 64 deletions

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "edge",
"version": "stable",
"request": "launch",
"name": "Launch Edge against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}

View File

@ -0,0 +1,83 @@
# Frontend Mentor - Intro component with sign up form
![Design preview for the Intro component with sign up form coding challenge](./design/desktop-preview.jpg)
## Welcome! 👋
Thanks for checking out this front-end coding challenge.
[Frontend Mentor](https://www.frontendmentor.io) challenges allow you to improve your skills in a real-life workflow.
**To do this challenge, you need a basic understanding of HTML, CSS and JavaScript.**
## The challenge
Your challenge is to build out this introductory component and get it looking as close to the design as possible.
You can use any tools you like to help you complete the challenge. So if you've got something you'd like to practice, feel free to give it a go.
Your users should be able to:
- View the optimal layout for the site depending on their device's screen size
- See hover states for all interactive elements on the page
- Receive an error message when the `form` is submitted if:
- Any `input` field is empty. The message for this error should say *"[Field Name] cannot be empty"*
- The email address is not formatted correctly (i.e. a correct email address should have this structure: `name@host.tld`). The message for this error should say *"Looks like this is not an email"*
Want some support on the challenge? [Join our Slack community](https://www.frontendmentor.io/slack) and ask questions in the **#help** channel.
## Where to find everything
Your task is to build out the project to the designs inside the `/design` folder. You will find both a mobile and a desktop version of the design to work to.
The designs are in JPG static format. This will mean that you'll need to use your best judgment for styles such as `font-size`, `padding` and `margin`. This should help train your eye to perceive differences in spacings and sizes.
If you would like the Sketch file in order to inspect the design in more detail it is available to [purchase here]().
You will find all the required assets in the `/images` folder. The assets are already optimized.
There is also a `style-guide.md` file, which contains the information you'll need, such as color palette and fonts.
## Building your project
Feel free to use any workflow that you feel comfortable with. Below is a suggested process, but do not feel like you need to follow these steps:
1. Initialize your project as a public repository on [GitHub](https://github.com/). This will make it easier to share your code with the community if you need some help. If you're not sure how to do this, [have a read through of this Try Git resource](https://try.github.io/).
2. Configure your repository to publish your code to a URL. This will also be useful if you need some help during a challenge as you can share the URL for your project with your repo URL. There are a number of ways to do this, but we recommend using [Vercel](https://bit.ly/fem-vercel). We've got more information about deploying your project with Vercel below.
3. Look through the designs to start planning out how you'll tackle the project. This step is crucial to help you think ahead for CSS classes that you could create to make reusable styles.
4. Before adding any styles, structure your content with HTML. Writing your HTML first can help focus your attention on creating well-structured content.
5. Write out the base styles for your project, including general content styles, such as `font-family` and `font-size`.
6. Start adding styles to the top of the page and work down. Only move on to the next section once you're happy you've completed the area you're working on.
7. If you'd like to try making your project fully responsive, we'd recommend checking out [Sizzy](https://bit.ly/fm-sizzy). It's a great browser that makes it easy to view your site across multiple devices.
## Deploying your project
As mentioned above, there are a number of ways to host your project for free. We recommend using [Vercel](https://bit.ly/fem-vercel) as it's an amazing service and extremely simple to get set up with. If you'd like to use Vercel, here are some steps to follow to get started:
1. [Sign up to Vercel](https://bit.ly/fem-vercel-signup) and go through the onboarding flow, ensuring your GitHub account is connected by using their [Vercel for GitHub](https://vercel.com/docs/v2/git-integrations/vercel-for-github) integration.
2. Connect your project to Vercel from the ["Import project" page](https://vercel.com/import), using the "From Git Repository" button and selecting the project you want to deploy.
3. Once connected, every time you `git push`, Vercel will create a new [deployment](https://vercel.com/docs/v2/platform/deployments) and the deployment URL will be shown on your [Dashboard](https://vercel.com/dashboard). You will also receive an email for each deployment with the URL.
## Sharing your solution
There are multiple places you can share your solution:
1. Submit it on the platform so that other users will see your solution on the site. Here's our ["Complete guide to submitting solutions"](https://medium.com/frontend-mentor/a-complete-guide-to-submitting-solutions-on-frontend-mentor-ac6384162248) to help you do that.
2. Share your solution page in the **#finished-projects** channel of the [Slack community](https://www.frontendmentor.io/slack).
3. Tweet [@frontendmentor](https://twitter.com/frontendmentor) and mention **@frontendmentor** including the repo and live URLs in the tweet. We'd love to take a look at what you've built and help share it around.
## Giving feedback
Feedback is always welcome, so if you have any to give on this challenge please email hi[at]frontendmentor[dot]io.
This challenge is completely free. Please share it with anyone who will find it useful for practice.
**Have fun building!** 🚀
## Community Sponsors
A massive thank you to our community sponsors!
- [Sizzy](https://bit.ly/fm-sizzy) is an extremely useful browser designed specifically to improve a developer's workflow when building websites. You can fire up multiple device emulators and run them all in sync while building out your web pages. Perfect for helping build fully responsive websites!
- [Diversify Tech](https://bit.ly/fem-diversify-tech) is an amazing resource for underrepresented people in tech. The site features job listings for anyone seeking new opportunities. The resource section is also full of useful links to dive into!
- [Dracula PRO](https://bit.ly/fem-dracula) is a beautiful dark theme to help keep you focused and productive while you code. The theme isn't just for your editor either. You can also apply it to your most-used apps like your terminal and even Slack!

View File

@ -1,22 +1,29 @@
# Frontend Mentor - Intro component with sign up form
# Frontend Mentor - Intro component with sign up form solution
![Design preview for the Intro component with sign up form coding challenge](./design/desktop-preview.jpg)
This is a solution to the [Intro component with sign up form challenge on Frontend Mentor](https://www.frontendmentor.io/challenges/intro-component-with-signup-form-5cf91bd49edda32581d28fd1). Frontend Mentor challenges help you improve your coding skills by building realistic projects.
## Welcome! 👋
## Table of contents
Thanks for checking out this front-end coding challenge.
- [Frontend Mentor - Intro component with sign up form solution](#frontend-mentor---intro-component-with-sign-up-form-solution)
- [Table of contents](#table-of-contents)
- [Overview](#overview)
- [The challenge](#the-challenge)
- [Screenshot](#screenshot)
- [Links](#links)
- [My process](#my-process)
- [Built with](#built-with)
- [What I learned](#what-i-learned)
- [Continued development](#continued-development)
- [Author](#author)
- [Acknowledgments](#acknowledgments)
[Frontend Mentor](https://www.frontendmentor.io) challenges allow you to improve your skills in a real-life workflow.
**Note: Delete this note and update the table of contents based on what sections you keep.**
**To do this challenge, you need a basic understanding of HTML, CSS and JavaScript.**
## Overview
## The challenge
### The challenge
Your challenge is to build out this introductory component and get it looking as close to the design as possible.
You can use any tools you like to help you complete the challenge. So if you've got something you'd like to practice, feel free to give it a go.
Your users should be able to:
Users should be able to:
- View the optimal layout for the site depending on their device's screen size
- See hover states for all interactive elements on the page
@ -24,60 +31,50 @@ Your users should be able to:
- Any `input` field is empty. The message for this error should say *"[Field Name] cannot be empty"*
- The email address is not formatted correctly (i.e. a correct email address should have this structure: `name@host.tld`). The message for this error should say *"Looks like this is not an email"*
Want some support on the challenge? [Join our Slack community](https://www.frontendmentor.io/slack) and ask questions in the **#help** channel.
### Screenshot
## Where to find everything
![Mobile](./screenshots/mobile.png)
![Mobile with Errors](./screenshots/mobile-errors.png)
![Desktop](./screenshots/desktop.png)
![Desktop with Errors](./screenshots/desktop-errors.png)
Your task is to build out the project to the designs inside the `/design` folder. You will find both a mobile and a desktop version of the design to work to.
These screenshots represent the Mobile and Destktop versions, with and without the error states.
The designs are in JPG static format. This will mean that you'll need to use your best judgment for styles such as `font-size`, `padding` and `margin`. This should help train your eye to perceive differences in spacings and sizes.
### Links
If you would like the Sketch file in order to inspect the design in more detail it is available to [purchase here]().
- Solution URL: [Github](https://github.com/tarasis/tarasis.github.io/tree/main/projects/FrontendMentor/newbie/intro-component-with-signup-form)
- Live Site URL: [Tarasis @ Github.io](https://tarasis.github.io/FrontendMentor/newbie/intro-component-with-signup-form/)
You will find all the required assets in the `/images` folder. The assets are already optimized.
## My process
There is also a `style-guide.md` file, which contains the information you'll need, such as color palette and fonts.
As usual I started with a mobile first approach, aiming to put most things into CSS properties, so that for the desktop version I was mostly just updating the values of the properties.
## Building your project
I'm not sure why I decided to not use a lot of classes, and instead put styling directly onto the html elements. I think it was just to be a little different than normal. I know that in a real project that I wouldn't use this approach.
Feel free to use any workflow that you feel comfortable with. Below is a suggested process, but do not feel like you need to follow these steps:
For the JavaScript I tried to minimise how much I was doing there, and looked to leverage combining text with an element id so I could unhide or hide the error message.
1. Initialize your project as a public repository on [GitHub](https://github.com/). This will make it easier to share your code with the community if you need some help. If you're not sure how to do this, [have a read through of this Try Git resource](https://try.github.io/).
2. Configure your repository to publish your code to a URL. This will also be useful if you need some help during a challenge as you can share the URL for your project with your repo URL. There are a number of ways to do this, but we recommend using [Vercel](https://bit.ly/fem-vercel). We've got more information about deploying your project with Vercel below.
3. Look through the designs to start planning out how you'll tackle the project. This step is crucial to help you think ahead for CSS classes that you could create to make reusable styles.
4. Before adding any styles, structure your content with HTML. Writing your HTML first can help focus your attention on creating well-structured content.
5. Write out the base styles for your project, including general content styles, such as `font-family` and `font-size`.
6. Start adding styles to the top of the page and work down. Only move on to the next section once you're happy you've completed the area you're working on.
7. If you'd like to try making your project fully responsive, we'd recommend checking out [Sizzy](https://bit.ly/fm-sizzy). It's a great browser that makes it easy to view your site across multiple devices.
### Built with
## Deploying your project
- Semantic HTML5 markup
- CSS custom properties
- Flexbox
- Mobile-first workflow
As mentioned above, there are a number of ways to host your project for free. We recommend using [Vercel](https://bit.ly/fem-vercel) as it's an amazing service and extremely simple to get set up with. If you'd like to use Vercel, here are some steps to follow to get started:
### What I learned
1. [Sign up to Vercel](https://bit.ly/fem-vercel-signup) and go through the onboarding flow, ensuring your GitHub account is connected by using their [Vercel for GitHub](https://vercel.com/docs/v2/git-integrations/vercel-for-github) integration.
2. Connect your project to Vercel from the ["Import project" page](https://vercel.com/import), using the "From Git Repository" button and selecting the project you want to deploy.
3. Once connected, every time you `git push`, Vercel will create a new [deployment](https://vercel.com/docs/v2/platform/deployments) and the deployment URL will be shown on your [Dashboard](https://vercel.com/dashboard). You will also receive an email for each deployment with the URL.
Main thing I learnt was that the `checkValidity()` method triggers checks for ALL HTML inputs on the page, not just the specific one you targeted. This surprised me, and was consistent across Safari, Firefox and Chrome.
## Sharing your solution
There are multiple places you can share your solution:
### Continued development
1. Submit it on the platform so that other users will see your solution on the site. Here's our ["Complete guide to submitting solutions"](https://medium.com/frontend-mentor/a-complete-guide-to-submitting-solutions-on-frontend-mentor-ac6384162248) to help you do that.
2. Share your solution page in the **#finished-projects** channel of the [Slack community](https://www.frontendmentor.io/slack).
3. Tweet [@frontendmentor](https://twitter.com/frontendmentor) and mention **@frontendmentor** including the repo and live URLs in the tweet. We'd love to take a look at what you've built and help share it around.
Continue working through challenges. I really must put some time into learning BEM / the version that Kevin Powell uses.
## Giving feedback
## Author
Feedback is always welcome, so if you have any to give on this challenge please email hi[at]frontendmentor[dot]io.
- Website - [Robert McGovern](https://tarasis.net)
- Frontend Mentor - [@tarasis](https://www.frontendmentor.io/profile/tarasis)
- Twitter - [@tarasis](https://www.twitter.com/tarasis)
This challenge is completely free. Please share it with anyone who will find it useful for practice.
## Acknowledgments
**Have fun building!** 🚀
## Community Sponsors
A massive thank you to our community sponsors!
- [Sizzy](https://bit.ly/fm-sizzy) is an extremely useful browser designed specifically to improve a developer's workflow when building websites. You can fire up multiple device emulators and run them all in sync while building out your web pages. Perfect for helping build fully responsive websites!
- [Diversify Tech](https://bit.ly/fem-diversify-tech) is an amazing resource for underrepresented people in tech. The site features job listings for anyone seeking new opportunities. The resource section is also full of useful links to dive into!
- [Dracula PRO](https://bit.ly/fem-dracula) is a beautiful dark theme to help keep you focused and productive while you code. The theme isn't just for your editor either. You can also apply it to your most-used apps like your terminal and even Slack!
Matt for this useful service.

View File

@ -58,6 +58,12 @@
--fw-terms-bold: 700;
--fw-terms: 500;
--fs-error: 11px;
--lh-error: 16px;
--fw-error: 500;
--font-style-error: italic;
--text-align-error: right;
--bg-image: url(../images/bg-intro-mobile.png);
--text-align: center;
@ -213,6 +219,29 @@ form p a {
color: var(--col-primary-background);
}
.errorMessage-styling {
font-size: var(--fs-error);
line-height: var(--lh-error);
font-weight: var(--fw-error);
font-style: var(--font-style-error);
text-align: var(--text-align-error);
margin: 0;
padding: 6px 0 0 0;
color: var(--col-primary-background);
}
.error-highlight {
outline: none;
border-color: var(--col-primary-background);
color: var(--col-primary-background);
background-image: url("../images/icon-error.svg");
background-repeat: no-repeat;
background-position: right 1rem center;
background-size: 1.3rem;
}
@media screen and (min-width: 800px) {
:root {
--fs-header: 50px;

View File

@ -37,12 +37,32 @@
<main>
<h2><span>Try it free 7 days</span> then $20/mo. thereafter</h2>
<form action="submit" onsubmit="return verifyData(this.form)">
<input type=" text" name="firstName" id="firstName" placeholder="First Name">
<input type="text" name="lastName" id="lastName" placeholder="Last Name">
<input type="email" name="email" id="email" placeholder="Email Address">
<input type="password" name="password" id="password" placeholder="Password">
<button onClick="verifyData(this.form)">Claim your free trial</button>
<form id="details-form" action="submit" novalidate>
<input type="text" name="firstName" id="firstNameInput" placeholder="First Name" enterkeyhint="next"
autocomplete="given-name" autofocus required>
<div class="errorSection" id="errorSection">
<!-- hidden -->
<p hidden class="errorMessage-styling" id="errorMessage-firstNameInput">First Name cannot be empty</p>
</div>
<input type="text" name="lastName" id="lastNameInput" placeholder="Last Name" enterkeyhint="next"
autocomplete="family-name" required>
<div class="errorSection" id="errorSection">
<!-- hidden -->
<p hidden class="errorMessage-styling" id="errorMessage-lastNameInput">Last Name cannot be empty</p>
</div>
<input type="email" name="email" id="emailInput" placeholder="Email Address" enterkeyhint="next"
autocomplete="email" required>
<div class="errorSection" id="errorSection">
<!-- hidden -->
<p hidden class="errorMessage-styling" id="errorMessage-emailInput">Looks like this is not an email</p>
</div>
<input type="password" name="password" id="passwordInput" placeholder="Password" enterkeyhint="done"
autocomplete="new-password" required>
<div class="errorSection" id="errorSection">
<!-- hidden -->
<p hidden class="errorMessage-styling" id="errorMessage-passwordInput">Password cannot be empty</p>
</div>
<button type="submit">Claim your free trial</button>
<p>
By clicking the button, you are agreeing to our <a href="#" rel="">Terms and Services</a>
</p>

View File

@ -1,11 +1,39 @@
function verifyData(form) {
console.log(typeof form);
"use strict";
return false;
const form = document.getElementById("details-form");
const inputs = document.querySelectorAll("input");
for (const input of inputs) {
// console.log(`${input.id} getting focus listener`)
input.addEventListener("focus", inputFocused, false);
}
form.addEventListener("submit", checkFormValidity, false);
/**
* @param {Event} event
*/
function checkFormValidity(event) {
if (form.checkValidity() === false) {
event.preventDefault();
const invalids = form.querySelectorAll(":invalid");
for (const input of invalids) {
// console.log(`${input.id} is invalid`);
// console.log(`${input.id} msg ${input.validationMessage}`);
// get the relevant error message element, using id of the input
let errorSection = document.getElementById(`errorMessage-${input.id}`)
// console.log(`ES: ${errorSection}, ${typeof (errorSection)} id: ${errorSection.id}`);
errorSection.removeAttribute("hidden");
input.classList.add("error-highlight")
}
}
}
function validateForm() {
console.log("Hello");
return false;
}
// When an input has focus I remove the error state,
// I could more ideally check if the class is in the classlist,
// and attribute hidden was false
function inputFocused(event) {
const input = event.currentTarget;
input.classList.remove("error-highlight");
let errorSection = document.getElementById(`errorMessage-${input.id}`);
errorSection.setAttribute("hidden", true);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 266 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

View File

@ -11,6 +11,18 @@
"title": "Newbie",
"cssClass": "frontEndMentorChallenges",
"challenges": [
{
"title": "Intro Component with Signup form",
"url": "/FrontendMentor/newbie/intro-component-with-signup-form/",
"description": "",
"techUsed": [
"html5",
"css3",
"js"
],
"screenshotURL": "/FrontendMentor/newbie/intro-component-with-signup-form/screenshots/mobile.png",
"screenshotAltText": "Intro Component Challenge from FrontendMentor"
},
{
"title": "FAQ Accordion Card",
"url": "/FrontendMentor/newbie/faq-accordion-card/",