From f01e6963776ec2c149ee81127b1510fab957a4c8 Mon Sep 17 00:00:00 2001 From: asabeneh Date: Tue, 13 Oct 2020 01:00:28 +0300 Subject: [PATCH] day_12 has been cleaned --- 12_Day_Forms/12_forms.md | 604 +++++++++--------- .../12_forms_boilerplate/src/index.js | 295 ++++----- 2 files changed, 458 insertions(+), 441 deletions(-) diff --git a/12_Day_Forms/12_forms.md b/12_Day_Forms/12_forms.md index b010c5c80d..ace0ce2339 100644 --- a/12_Day_Forms/12_forms.md +++ b/12_Day_Forms/12_forms.md @@ -19,7 +19,7 @@ ![30 Days of React banner](../images/30_days_of_react_banner_day_12.jpg) - [Forms](#forms) - - [Getting data from input field](#getting-data-from-input-field) + - [Getting data from an input field](#getting-data-from-an-input-field) - [Getting multiple input data from form](#getting-multiple-input-data-from-form) - [Get data from different input field types](#get-data-from-different-input-field-types) - [Form Validation](#form-validation) @@ -33,7 +33,7 @@ # Forms -Form is used to collect data from user. Once in a while we use form to fill our information on a paper or on a website. Either to sign up, sign in or to apply for a job we fill different form fields to submit data to remote database. We encounter different form fields when we fill a form such as simple text, email, password, telephone, date, checkbox, radio button, option selection and text area field. Currently, HTML5 has provide quite a lot of field types. You may have +Form is used to collect data from a user. Once in a while we use form to fill our information on a paper or on a website. Either to sign up, sign in or to apply for a job we fill different form fields to submit our data to remote database. We encounter different form fields when we fill a form such as simple text, email, password, telephone, date, checkbox, radio button, option selection and text area field. Currently, HTML5 has provide quite a lot of field types. You may have a look at the following available HTML5 input types. ```html @@ -67,7 +67,7 @@ Form is used to collect data from user. Once in a while we use form to fill our ``` -Another HTML fields to get data from form are textarea and options. +Another HTML fields to get data from a form are textarea and select with options elements. ```html @@ -82,9 +82,9 @@ Another HTML fields to get data from form are textarea and options. ``` -Now, you know most of fields we need to get data from a form. Let's start with an input of type text field. In the previous day, we saw different types of events and today we will focus on more of _onChange_ event type which triggers whenever an input field data changes. Input field has by default a memory to store input data but in this section we control that using state and we implement a controlled input. Today we will implement a controlled input. We will cover uncontrolled input in a separate section. +Now, you know most of the fields we need to get data from a form. Let's start with an input with type text field. In the previous day, we saw different types of events and today we will focus on more of _onChange_ event type which triggers whenever an input field data changes. Input field has by default a memory to store input data but in this section we control that using state and we implement a controlled input. Today we will implement a controlled input. We will cover uncontrolled input in a separate section. -## Getting data from input field +## Getting data from an input field So far we did not get any data from input field. Now, it is time to learn how to get data from an input field. We need on input field, event listener (onChange) and state to get data from a controlled input. See the example below. The h1 element below the input tag display what we write on the input. Check live [demo](https://codepen.io/Asabeneh/full/OJVpyqm). @@ -208,7 +208,7 @@ class App extends React.Component { } ``` -The above form handles only text types but can handle different input field types. Let's do another form which handle all the different input field types. +The above form handles only text types but do have different input field types. Let's do another form which handle all the different input field types. ## Get data from different input field types @@ -289,11 +289,14 @@ class App extends React.Component { handleSubmit = (e) => { // stops the default behavior of form element specifically refreshing of page e.preventDefault() - e.preventDefault() const { firstName, lastName, email, + tel, + dateOfBirth, + favoriteColor, + weight, country, gender, bio, @@ -312,6 +315,10 @@ class App extends React.Component { firstName, lastName, email, + tel, + dateOfBirth, + favoriteColor, + weight, country, gender, bio, @@ -323,183 +330,191 @@ class App extends React.Component { render() { // accessing the state value by destrutcturing the state - const { firstName, lastName, title, country } = this.state + const { + firstName, + lastName, + email, + tel, + dateOfBirth, + favoriteColor, + weight, + country, + gender, + bio, + } = this.state return (

Add Student

-
- React Form and Form Validation -
-
- - -
-
- - -
-
- - -
-
- +
- +
-
- +
- +
-
- +
+ +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +
+

Gender

+
+
-
- + +
-
-

Gender

-
- - -
-
- - -
-
- - -
+ +
+
+
+

Select your skills

-

Select your skills

-
- - -
-
- - -
-
- - -
-
-
-
-