-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathForm.js
61 lines (54 loc) · 1.87 KB
/
Form.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, { useEffect, useState } from 'react'
// 👇 Here are the validation errors you will use with Yup.
const validationErrors = {
fullNameTooShort: 'full name must be at least 3 characters',
fullNameTooLong: 'full name must be at most 20 characters',
sizeIncorrect: 'size must be S or M or L'
}
// 👇 Here you will create your schema.
// 👇 This array could help you construct your checkboxes using .map in the JSX.
const toppings = [
{ topping_id: '1', text: 'Pepperoni' },
{ topping_id: '2', text: 'Green Peppers' },
{ topping_id: '3', text: 'Pineapple' },
{ topping_id: '4', text: 'Mushrooms' },
{ topping_id: '5', text: 'Ham' },
]
export default function Form() {
return (
<form>
<h2>Order Your Pizza</h2>
{true && <div className='success'>Thank you for your order!</div>}
{true && <div className='failure'>Something went wrong</div>}
<div className="input-group">
<div>
<label htmlFor="fullName">Full Name</label><br />
<input placeholder="Type full name" id="fullName" type="text" />
</div>
{true && <div className='error'>Bad value</div>}
</div>
<div className="input-group">
<div>
<label htmlFor="size">Size</label><br />
<select id="size">
<option value="">----Choose Size----</option>
{/* Fill out the missing options */}
</select>
</div>
{true && <div className='error'>Bad value</div>}
</div>
<div className="input-group">
{/* 👇 Maybe you could generate the checkboxes dynamically */}
<label key="1">
<input
name="Pepperoni"
type="checkbox"
/>
Pepperoni<br />
</label>
</div>
{/* 👇 Make sure the submit stays disabled until the form validates! */}
<input type="submit" />
</form>
)
}