-
Notifications
You must be signed in to change notification settings - Fork 1
/
sampleForm.js
168 lines (151 loc) · 6.56 KB
/
sampleForm.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Importing the node modules, child components, services and controllers used
inside IntranetHome component */
import React from 'react';
import { Component } from 'react';
import $ from "jquery";
import { Link } from 'react-router-dom';
import axios from 'axios';
import update from 'react-addons-update';
/* IntranetHome Component initialization */
class SampleForm extends Component {
/* Initializing objects of its IntranetHome class */
constructor(props) {
super(props)
this.state = {
form_index:-1,
firstname: '',
lastname: '',
gender: '',
password:'',
newdata:[]
}
}
componentDidMount() {
}
setValue(field, e) {
var object = {};
object[field] = e.target.value;
this.setState(object);
}
saveData(){
const obj = {
'firstName': this.state.firstname,
'lastName': this.state.lastname,
'Gender': this.state.gender,
'Password': this.state.password
}
this.state.newdata.push(obj)
this.setState({ newdata: this.state.newdata});
}
/* It is invoked to return html content */
render() {
var tableStyle = {
border: '1px solid #ccc',
border_collapse: 'collapse',
width: '80%',
margin: '2% auto'
};
var thstyle = {
borderRight: '1px solid #ccc',
width: 'auto',
padding: '8px',
background: '#000',
color: '#fff'
}
var trstyle = {
border: '1px solid #ccc'
}
var tdstyle = {
borderRight: '1px solid #ccc',
width: 'auto',
padding: '8px'
}
var norecords = {
textAlign: 'center',
color: '#ff0000',
fontWeight: 'bolder',
padding: '10px'
}
var addMoreToAdd = {
verticalAlign: 'middle',
width: 'auto',
margin: 'auto',
textAlign: 'center',
border: '1px solid #ccc',
padding: '10px'
}
var itest = {
border: '1px solid #ccc',
margin: '10px 6px',
padding: '5px',
verticalAlign: 'middle'
}
//console.log(this.state.firstname,this.state.lastname,this.state.gender,this.state.password);
return (
<div>
<table style={tableStyle}>
<thead>
<th style={thstyle}>firstname</th>
<th style={thstyle}>lastname</th>
<th style={thstyle}>Gender</th>
<th style={thstyle}>Password</th>
</thead>
{this.state.newdata.length > 0 ? this.state.newdata.map((dynamicComponent, index) => <tbody key={index}>
<tr style={trstyle}>
<td style={tdstyle}>{dynamicComponent.firstName}</td>
<td style={tdstyle}>{dynamicComponent.lastName}</td>
<td style={tdstyle}>{dynamicComponent.Gender}</td>
<td style={tdstyle}>{dynamicComponent.Password}</td>
{/* <td style={tdstyle}>
<button onClick={this.onEditclick.bind(this, dynamicComponent, index)} data-toggle="modal" data-target="#listViewModal" className="btn"><i className="fa fa-pencil" aria-hidden="true"></i></button>
<button onClick={this.onDeleteclick.bind(this, index)} data-toggle="modal" data-target="#deleteModal" className="btn btn-danger"><i className="fa fa-times" aria-hidden="true"></i></button>
</td> */}
</tr>
</tbody>) : <tbody><tr style={trstyle}><td style={norecords} colSpan="4">No Records</td></tr></tbody>}
</table>
<div className="container">
<form>
<div className="row">
<div className="col-25">
<label htmlFor="fname">First Name</label>
</div>
<div className="col-75">
<input type="text" id="fname" name="firstname" placeholder="Your name.." onChange={this.setValue.bind(this, 'firstname')} value={this.state.firstname} />
</div>
</div>
<div className="row">
<div className="col-25">
<label htmlFor="lname">Last Name</label>
</div>
<div className="col-75">
<input type="text" id="lname" name="lastname" onChange={this.setValue.bind(this, 'lastname')} value={this.state.lastname} placeholder="Your last name.." />
</div>
</div>
<div className="row">
<div className="col-25">
<label htmlFor="country">Gender</label>
</div>
<div className="col-75">
<select id="gender" name="gender" onChange={this.setValue.bind(this,'gender')} >
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div>
<div className="row">
<div className="col-25">
<label htmlFor="lname">Password</label>
</div>
<div className="col-75">
<input type="password" id="password" name="password" onChange={this.setValue.bind(this, 'password')} value={this.state.password} placeholder="Password.." />
</div>
</div>
<button type="button" className="btn btn-primary" onClick={this.saveData.bind(this)}>Add to List</button>
{/* <input type="submit" value="Submit" /> */}
</form>
</div>
</div>
);
}
}
export default SampleForm;