forked from AdaGold/exquisite-react
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPlayerSubmissionForm.js
More file actions
100 lines (71 loc) · 1.92 KB
/
Copy pathPlayerSubmissionForm.js
File metadata and controls
100 lines (71 loc) · 1.92 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import React, { Component } from 'react';
import './PlayerSubmissionForm.css';
class PlayerSubmissionForm extends Component {
fieldState = () => {
let fieldState = {}
this.props.fields.forEach((field) => {
if(field.key) {
fieldState[field.key] = ""
}
})
return fieldState
}
constructor(props) {
super(props);
this.state = this.fieldState()
}
onInputChange = (event) => {
const updatedState = {};
const field = event.target.name;
const value = event.target.value;
updatedState[field] = value;
this.setState(updatedState);
}
checkSubmission = () => {
let check = true
this.props.fields.forEach((field) => {
if (field === ""){
check = false
}
})
return check
}
onSubmit = (event) => {
event.preventDefault();
if (this.checkSubmission()) {
this.props.addLineCallback(this.state)
}
this.setState(this.fieldState());
}
render() {
console.log(this.state)
const playerForm = this.props.fields.map((field, i) => {
if(field.key) {
return(<input
key={i}
placeholder={field.placeholder}
name={field.key}
value={this.state[field.key]}
onChange={this.onInputChange}
type="text" />
)
}else{
return field
}
})
return (
<div className="PlayerSubmissionForm">
<h3>Player Submission Form for Player #{ this.props.playerNum}</h3>
<form onSubmit={this.onSubmit} className="PlayerSubmissionForm__form" >
<div className="PlayerSubmissionForm__poem-inputs">
{playerForm}
</div>
<div className="PlayerSubmissionForm__submit">
<input type="submit" value="Submit Line"className="PlayerSubmissionForm__submit-btn" />
</div>
</form>
</div>
);
}
}
export default PlayerSubmissionForm;