From 240c95cc67f8debd4f8724bfdedb3f79fb5426b2 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Sat, 15 Aug 2020 12:59:49 -0400 Subject: [PATCH 01/15] Add solutions for the Select checkpoint --- index.js | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/index.js b/index.js index e69de29b..fcf7a819 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,65 @@ +// view the entire HTML document +console.log(document); + +// find an

element +const heading = document.querySelector("h1"); +console.log(heading); + +// find an element with the class "value" +const elem01 = document.querySelector(".value"); +console.log(elem01); + +// find a + + +

Biscayne National Park

diff --git a/style.css b/style.css index 64f9755a..e788a59e 100644 --- a/style.css +++ b/style.css @@ -105,6 +105,31 @@ main { color: rgba(255, 255, 255, 0.5); } +.inputForm { + width: 90%; + max-width: 350px; + padding: 6px; + margin: 6px auto; + background-color: rgba(0, 0, 0, 0.1); + box-shadow: 0 0 3px 1px rgba(0, 0, 0, 0.3); +} + +.inputForm label { + font-weight: bold; + display: block; + margin-top: 4px; +} + +.inputForm input, +.inputForm textarea { + width: 100%; +} + +.inputForm .formControl { + padding: 6px; + text-align: center; +} + @media screen and (min-width: 600px) { main { grid-template-columns: repeat(2, 1fr); From 4135a3dfce1ef80d6d9decc1991d36460a928c39 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Sun, 16 Aug 2020 21:04:12 -0400 Subject: [PATCH 05/15] Add error messages for the form. --- index.html | 8 ++++++++ style.css | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/index.html b/index.html index 8a856e1d..7c288c02 100644 --- a/index.html +++ b/index.html @@ -21,6 +21,7 @@

Add a new park

title="Park name" placeholder="Name of park" /> +
Please enter a name
Add a new park

title="Park location" placeholder="State, United States" /> +
Please enter a location
+
+ Please enter a short description +
Add a new park title="Established" placeholder="July 4, 1776" /> +
Please enter a date
Add a new park title="Area" placeholder="1 acre" /> +
Please enter a name
Add a new park title="rating" placeholder="4.9" /> +
Please enter a name
diff --git a/style.css b/style.css index e788a59e..97207c46 100644 --- a/style.css +++ b/style.css @@ -130,6 +130,12 @@ main { text-align: center; } +.inputForm .error { + font-size: 0.8rem; + color: #bb0000; + display: none; +} + @media screen and (min-width: 600px) { main { grid-template-columns: repeat(2, 1fr); From 52d282f05df69726978dd34da56318e522ab4448 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Sun, 16 Aug 2020 21:47:15 -0400 Subject: [PATCH 06/15] Update form names and fixed error messages --- index.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 7c288c02..9c9f2383 100644 --- a/index.html +++ b/index.html @@ -39,7 +39,7 @@

Add a new park

Add a new park -
Please enter a name
+
Please enter the area
-
Please enter a name
+
+ Please enter the rating between 1 and 5 inclusive. +
From 53e81988e8d62a1cf0e4408c37c2c8c75e994291 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Fri, 21 Aug 2020 09:35:20 -0400 Subject: [PATCH 07/15] Updated README --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f89ba8a2..4afb3a7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # National Parks -_Sample project for Front End Web Development course at Thinkful_ +_Starter project for Front End Web Development JavaScript and the DOM module_ ## Introduction @@ -8,22 +8,24 @@ This starter project is used for illustrating the DOM and using JavaScript to in ## View Demo -For a demonstration of the page visit [this link](https://vramdhanie.github.io/national_parks/). +For a demonstration of the page visit [this link](https://thinkful-ed.github.io/starter-national-parks/). ## Getting started -Clone this repository to your local machine. +Fork this repository then clone your fork to your local machine. ```bash -git clone https://github.com/vramdhanie/national_parks.git +git clone https://github.com//starter-national-parks.git ``` -Navigate to the folder containing the repository and start a local server: +Navigate to the folder containing the repository and start a local server. For example you may use _lite-server_. ```bash npx lite-server ``` +> **lite-server** is a lightweight _development only_ node server that serves a web app, opens it in the browser, and refreshes when html or javascript changes occur. + Open the code in your favourite editor. For instance, to open VSCode: ```bash From f5bc4973a36b9c1347359a94aaa1c24cb8df2157 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Fri, 21 Aug 2020 09:42:56 -0400 Subject: [PATCH 08/15] Updated README --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f89ba8a2..4afb3a7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # National Parks -_Sample project for Front End Web Development course at Thinkful_ +_Starter project for Front End Web Development JavaScript and the DOM module_ ## Introduction @@ -8,22 +8,24 @@ This starter project is used for illustrating the DOM and using JavaScript to in ## View Demo -For a demonstration of the page visit [this link](https://vramdhanie.github.io/national_parks/). +For a demonstration of the page visit [this link](https://thinkful-ed.github.io/starter-national-parks/). ## Getting started -Clone this repository to your local machine. +Fork this repository then clone your fork to your local machine. ```bash -git clone https://github.com/vramdhanie/national_parks.git +git clone https://github.com//starter-national-parks.git ``` -Navigate to the folder containing the repository and start a local server: +Navigate to the folder containing the repository and start a local server. For example you may use _lite-server_. ```bash npx lite-server ``` +> **lite-server** is a lightweight _development only_ node server that serves a web app, opens it in the browser, and refreshes when html or javascript changes occur. + Open the code in your favourite editor. For instance, to open VSCode: ```bash From a51d5716bb71713d85c6a26a2a762f1925b788dd Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Fri, 21 Aug 2020 09:49:49 -0400 Subject: [PATCH 09/15] Updated README --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f89ba8a2..4afb3a7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # National Parks -_Sample project for Front End Web Development course at Thinkful_ +_Starter project for Front End Web Development JavaScript and the DOM module_ ## Introduction @@ -8,22 +8,24 @@ This starter project is used for illustrating the DOM and using JavaScript to in ## View Demo -For a demonstration of the page visit [this link](https://vramdhanie.github.io/national_parks/). +For a demonstration of the page visit [this link](https://thinkful-ed.github.io/starter-national-parks/). ## Getting started -Clone this repository to your local machine. +Fork this repository then clone your fork to your local machine. ```bash -git clone https://github.com/vramdhanie/national_parks.git +git clone https://github.com//starter-national-parks.git ``` -Navigate to the folder containing the repository and start a local server: +Navigate to the folder containing the repository and start a local server. For example you may use _lite-server_. ```bash npx lite-server ``` +> **lite-server** is a lightweight _development only_ node server that serves a web app, opens it in the browser, and refreshes when html or javascript changes occur. + Open the code in your favourite editor. For instance, to open VSCode: ```bash From ac05371136d72109964b845186c2067d8d5342c4 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Fri, 21 Aug 2020 09:51:10 -0400 Subject: [PATCH 10/15] Updated README --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f89ba8a2..4afb3a7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # National Parks -_Sample project for Front End Web Development course at Thinkful_ +_Starter project for Front End Web Development JavaScript and the DOM module_ ## Introduction @@ -8,22 +8,24 @@ This starter project is used for illustrating the DOM and using JavaScript to in ## View Demo -For a demonstration of the page visit [this link](https://vramdhanie.github.io/national_parks/). +For a demonstration of the page visit [this link](https://thinkful-ed.github.io/starter-national-parks/). ## Getting started -Clone this repository to your local machine. +Fork this repository then clone your fork to your local machine. ```bash -git clone https://github.com/vramdhanie/national_parks.git +git clone https://github.com//starter-national-parks.git ``` -Navigate to the folder containing the repository and start a local server: +Navigate to the folder containing the repository and start a local server. For example you may use _lite-server_. ```bash npx lite-server ``` +> **lite-server** is a lightweight _development only_ node server that serves a web app, opens it in the browser, and refreshes when html or javascript changes occur. + Open the code in your favourite editor. For instance, to open VSCode: ```bash From 43bbb3829128b906eb68d0f8eddad9c5db77c392 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Fri, 21 Aug 2020 12:12:19 -0400 Subject: [PATCH 11/15] Fix class names to be kebab-case --- index.js | 4 ++-- style.css | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index eafac686..f9870c3a 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ for (rating of ratings) { let ratingValue = parseFloat(rating.innerText); if (ratingValue > 4.7) { - rating.classList.add("high_rating"); + rating.classList.add("high-rating"); rating.classList.remove("value"); } } @@ -36,7 +36,7 @@ const newElement = document.createElement("div"); newElement.innerText = `${numberParks} exciting parks to visit`; //add the class -newElement.classList.add("header_statement"); +newElement.classList.add("header-statement"); // insert the new element const header = document.querySelector("header"); diff --git a/style.css b/style.css index 24c8cbbd..a015f9a2 100644 --- a/style.css +++ b/style.css @@ -105,7 +105,7 @@ main { color: rgba(255, 255, 255, 0.5); } -.high_rating { +.high-rating { color: #3ba17c; font-size: 1.5rem; font-weight: bold; @@ -113,7 +113,7 @@ main { text-align: center; } -.header_statement { +.header-statement { color: #ffffff; font-size: 1.2rem; } From f65db10634dac0b644cf00d3925175f0701b7a67 Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Fri, 21 Aug 2020 12:25:16 -0400 Subject: [PATCH 12/15] Add missing let keyword --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index f9870c3a..5bc4303a 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ const descriptions = document.querySelectorAll(".description"); -for (desc of descriptions.values()) { +for (let desc of descriptions.values()) { let content = desc.innerText; if (content.length > 250) { @@ -16,7 +16,7 @@ for (desc of descriptions.values()) { // select all rating values const ratings = document.querySelectorAll(".rating .value"); -for (rating of ratings) { +for (let rating of ratings) { let ratingValue = parseFloat(rating.innerText); if (ratingValue > 4.7) { From 154273b16c624600956743641dce28aa42f2376c Mon Sep 17 00:00:00 2001 From: Vincent Ramdhanie Date: Wed, 25 Nov 2020 11:11:58 -0400 Subject: [PATCH 13/15] Update HTML file with structure to support validation --- index.html | 154 +++++++++++++++++++++++++---------------------------- 1 file changed, 74 insertions(+), 80 deletions(-) diff --git a/index.html b/index.html index 9c9f2383..c3c60f13 100644 --- a/index.html +++ b/index.html @@ -12,60 +12,72 @@

National Parks

Add a new park

-
- - -
Please enter a name
- - -
Please enter a location
- - -
- Please enter a short description + +
+ + +
Please enter a name
- - -
Please enter a date
- - -
Please enter the area
- - -
- Please enter the rating between 1 and 5 inclusive. +
+ + +
Please enter a location
+
+
+ + +
+ Please enter a short description +
+
+
+ + +
Please enter a date
+
+
+ + +
Please enter the area
+
+
+ + +
+ Please enter the rating between 1 and 5 inclusive. +
@@ -89,21 +101,15 @@

Biscayne National Park

Established

-
- June 28, 1980 -
+
June 28, 1980

Area

-
- 172,971 acres (699.99 km2) -
+
172,971 acres (699.99 km2)

Rating

-
- 4.7 -
+
4.7
@@ -123,9 +129,7 @@

Grand Canyon National Park

Established

-
- February 26, 1919 -
+
February 26, 1919

Area

@@ -133,9 +137,7 @@

Area

Rating

-
- 4.8 -
+
4.8
@@ -153,9 +155,7 @@

Gateway Arch National Park

Established

-
- February 22, 2018 -
+
February 22, 2018

Area

@@ -163,9 +163,7 @@

Area

Rating

-
- 4.7 -
+
4.7
@@ -184,9 +182,7 @@

Indiana Dunes National Park

Established

-
- February 15, 2019 -
+
February 15, 2019

Area

@@ -194,9 +190,7 @@

Area

Rating

-
- 4.6 -
+
4.6
From d934eb007672317d2ed582c6138da63a813092ef Mon Sep 17 00:00:00 2001 From: Gabriel Sanchez Date: Mon, 12 Dec 2022 10:35:48 -0600 Subject: [PATCH 14/15] add moment library script to starter code --- index.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.html b/index.html index 988d8abc..7c9ca5ed 100644 --- a/index.html +++ b/index.html @@ -190,6 +190,11 @@

Rating

+ From f36d847bc495bfe3040670639d655efd0d9391dc Mon Sep 17 00:00:00 2001 From: Leonardo Ritts Date: Fri, 26 Apr 2024 19:39:54 -0400 Subject: [PATCH 15/15] Worked on all the steps of the lesson to work on Forms --- index.js | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) diff --git a/index.js b/index.js index 8b137891..e26157a1 100644 --- a/index.js +++ b/index.js @@ -1 +1,135 @@ +// const submitHandler = (event) => { +// event.preventDefault(); +// console.log("The form was submitted"); +// //Get the name input +// const parkName = document.querySelector("#name-input").value; +// console.log(parkName); +// }; +const main = () => { + //Get the form element + const form = document.querySelector("#park-form"); + //Attach the submit handler + form.addEventListener("submit", submitHandler); +}; +window.addEventListener("DOMContentLoaded", main); + +function validateNumber(value) { + return !isNaN(value); +} + +function validateRange(value, min, max) { + return value >= min && value <= max; +} + +const submitHandler = (event) => { + event.preventDefault(); + + const form = event.target; + const formData = new FormData(form); + + const errors = validateForm(formData); + + //clear all previous errors + const errorElements = document.querySelectorAll(".error"); + for (let element of errorElements) { + element.style.display = "none"; + } + + //Display any new errors + Object.keys(errors).forEach((key) => { + //Fidn the specific error element + const errorElement = document.querySelector(`#${key}-form .error`); + errorElement.innerHTML = errors[key]; + errorElement.style.display = "block"; + }); + + // If there are no errors + if (!Object.keys(errors).length) { + // Create a new element + const parkSection = document.createElement("section"); + + // Add the park class + parkSection.classList.add("park-display"); + + // Construct the HTML for this element + const content = ` +

${formData.get("name")}

+
${formData.get("location")}
+
${formData.get("description")}
+ +
+
+

Established

+
${moment(formData.get("established")).format( + "MMMM D, YYYY" + )}
+
+
+

Area

+
${formData.get("area")}
+
+
+

Rating

+
${formData.get("rating")}
+
+
+ `; + + // Set the innerHTML + parkSection.innerHTML = content; + + // Append to the main element + document.querySelector("main").appendChild(parkSection); + } +}; +function validateExists(value) { + return value && value.trim(); +} +function validateForm(formData) { + const errors = {}; + + // Check if name was entered + if (!validateExists(formData.get("name"))) { + errors.name = "Please enter a name"; + } + + // Check if rating was entered + if (!validateExists(formData.get("rating"))) { + errors.rating = "Please enter a rating"; + } else { + // Check if the rating is a number + if (!validateNumber(formData.get("rating"))) { + errors.rating = "Rating must be a number"; + } else { + // Because it is a number, convert it + const rating = Number.parseFloat(formData.get("rating")); + // Check that the rating is between 1 and 5, inclusive + if (!validateRange(rating, 1, 5)) { + errors.rating = "Rating must be between 1 and 5 inclusive"; + } + } + } + + // Check if description was entered + if (!validateExists(formData.get("description"))) { + errors.description = "Please enter short description"; + } + + // Check if established date was entered + if (!validateExists(formData.get("established"))) { + errors.established = "Please enter date"; + } + + // Check if area was entered + if (!validateExists(formData.get("area"))) { + errors.area = "Please enter the area of the park"; + } + + // Check if location date was entered + if (!validateExists(formData.get("location"))) { + errors.location = "Please enter the location of the park"; + } + + return errors; +}