-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm.js
41 lines (34 loc) · 1.28 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
import React from 'react'
import { connect } from 'react-redux'
import * as actionCreators from '../state/action-creators'
export function Form(props) {
const { newQuestion, newTrueAnswer, newFalseAnswer } = props.form;
const onChange = evt => {
const { value } = evt.target
const key = evt.target.id
props.inputChange({ key, value })
}
const disabled = () => {
if(!newQuestion || !newTrueAnswer || !newFalseAnswer) {
return true
} else {
return false
}
}
const onSubmit = evt => {
evt.preventDefault()
// console.log('props', props);
props.postQuiz(props.form)
}
// const message = `Congrats: "${newQuestion}" is a great question!`
return (
<form id="form" onSubmit={onSubmit}>
<h2>Create New Quiz</h2>
<input maxLength={50} onChange={onChange} value={newQuestion} id="newQuestion" placeholder="Enter question" />
<input maxLength={50} onChange={onChange} value={newTrueAnswer} id="newTrueAnswer" placeholder="Enter true answer" />
<input maxLength={50} onChange={onChange} value={newFalseAnswer} id="newFalseAnswer" placeholder="Enter false answer" />
<button id="submitNewQuizBtn" disabled={disabled()}>Submit new quiz</button>
</form>
)
}
export default connect(st => st, actionCreators)(Form)