-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform-uncontrolled.htm
More file actions
70 lines (59 loc) · 1.6 KB
/
Copy pathform-uncontrolled.htm
File metadata and controls
70 lines (59 loc) · 1.6 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>React Uncontrolled Form</title>
</head>
<body>
<div id="root"></div>
<script src="https://unpkg.com/react@15/dist/react.js"></script>
<script src="https://unpkg.com/react-dom@15/dist/react-dom.js"></script>
<script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
<script type="text/jsx">
class NameForm extends React.Component {
constructor(props) {
super(props);
this.handleNameChange = this.handleNameChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleNameChange(event) {
// This is DOM manipulation
this.name.value = this.name.value.toUpperCase();
}
handleSubmit(event) {
alert(this.name.value + '\n' + this.sex.value + '\n' + this.address.value);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<label>
Name:
<input type="text" ref={input => this.name = input} onChange={this.handleNameChange} />
</label>
<br/>
<label>
Sex:
<select ref={input => this.sex = input} >
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</label>
<br/>
<label>
Address:
<textarea ref={input => this.address = input} />
</label>
<br/>
<input type="submit" value="Submit" />
</form>
);
}
}
ReactDOM.render(
<NameForm />,
document.getElementById('root')
);
</script>
</body>
</html>