Created
February 13, 2018 18:54
-
-
Save jtomchak/9a94bb5bb1fba94b0281fd884caaac04 to your computer and use it in GitHub Desktop.
Form Exercise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //////////////////////////////////////////////////////////////////////////////// | |
| // Exercise | |
| // | |
| // - When the checkbox is checked: | |
| // - Fill in the shipping fields with the values from billing | |
| // - Disable the shipping fields so they are not directly editable | |
| // - Keep the shipping fields up to date as billing fields change | |
| // - Hint: you can get the checkbox value from `event.target.checked` | |
| // - When the form submits, console.log the values | |
| // | |
| // Got extra time? | |
| // | |
| // - If there are more than two characters in the "state" field, let the user | |
| // know they should use the two-character abbreviation | |
| // - If the user types something into shipping, then checks the checkbox, then | |
| // unchecks the checkbox, ensure the field has the information from | |
| // before clicking the checkbox the first time | |
| import React, { Component } from "react"; | |
| class CheckoutForm extends Component { | |
| render() { | |
| return ( | |
| <div> | |
| <h1>Checkout</h1> | |
| <form> | |
| <fieldset> | |
| <legend>Billing Address</legend> | |
| <p> | |
| <label> | |
| Billing Name: <input type="text" /> | |
| </label> | |
| </p> | |
| <p> | |
| <label> | |
| Billing State: <input type="text" size="2" /> | |
| </label> | |
| </p> | |
| </fieldset> | |
| <br /> | |
| <fieldset> | |
| <label> | |
| <input type="checkbox" /> Same as billing | |
| </label> | |
| <legend>Shipping Address</legend> | |
| <p> | |
| <label> | |
| Shipping Name: <input type="text" /> | |
| </label> | |
| </p> | |
| <p> | |
| <label> | |
| Shipping State: <input type="text" size="2" /> | |
| </label> | |
| </p> | |
| </fieldset> | |
| <p> | |
| <button>Submit</button> | |
| </p> | |
| </form> | |
| </div> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment