/
signup-bootstrap.html
151 lines (142 loc) · 6.6 KB
/
signup-bootstrap.html
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
<!DOCTYPE html>
<html>
<head>
<title>Superform - SignUp Form Bootstrap Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<style>
.panel-signup {
margin: 60px auto;
}
</style>
</head>
<body>
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.14.7/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.5.0/lodash.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/validator/4.0.5/validator.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.34/browser.js"></script>
<script src="../lib/react-superform.js"></script>
<script type="text/babel">
class MyForm extends Superform {
onSuccessSubmit(data) {
console.log(data);
}
onErrorSubmit(errors, data) {
console.log(errors, data);
}
render() {
return (
<div className="container">
<div className="col-xs-12 col-md-6 col-md-offset-3">
<form noValidate onSubmit={ this.handleSubmit.bind(this) }>
<div
className={`panel panel-signup
${!this.isSubmited() ? "panel-primary": ""}
${this.isSubmited() && this.isFormValid() ? "panel-success": ""}
${this.isSubmited() && !this.isFormValid() ? "panel-danger": ""}
`}>
<div className="panel-heading">Sign up</div>
<div className="panel-body">
<div className={`form-group ${this.getErrorMessageOf("email") ? "has-error" : "" }`}>
<label className="control-label" htmlFor="email">Email</label>
<input
className="form-control"
type="email"
id="email"
name="email"
ref="email"
value={ this.getValueOf("email") }
onChange={ this.handleChange.bind(this) }
required
/>
<span className="help-block">{ this.getErrorMessageOf("email") }</span>
</div>
<div className={`form-group ${this.getErrorMessageOf("password") ? "has-error" : "" }`}>
<label className="control-label" htmlFor="password">Password</label>
<input
type="password"
className="form-control"
id="password"
ref="password"
name="password"
value={ this.getValueOf("password") }
onChange={ this.handleChange.bind(this) }
pattern="(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).*"
data-messages={JSON.stringify({
pattern: "Password must contain at least one digit, upper case and lower case letter",
minLength: "Password must contain at least :data characters"
})}
minLength="8"
required
/>
<span className="help-block">{ this.getErrorMessageOf("password") }</span>
</div>
<div className={`form-group ${this.getErrorMessageOf("repeatPassword") ? "has-error" : "" }`}>
<label className="control-label" htmlFor="repeatPassword">Repeat Password</label>
<input
className="form-control"
type="password"
id="repeatPassword"
name="repeatPassword"
ref="repeatPassword"
value={ this.getValueOf("repeatPassword") }
onChange={ this.handleChange.bind(this) }
data-equals="password"
data-messages={JSON.stringify({
equals: "Passwords doesn't match"
})}
required
/>
<span className="help-block">{ this.getErrorMessageOf("repeatPassword") }</span>
</div>
<div className={`form-group ${this.getErrorMessageOf("mood") ? "has-error" : "" }`}>
<label className="control-label" htmlFor="mood">Mood</label>
<select
className="form-control"
id="mood"
name="mood"
ref="mood"
value={ this.getValueOf("mood") }
onChange={ this.handleChange.bind(this) }
required
>
<option value="">Select…</option>
<option value="Happy">Happy</option>
<option value="Cool">Cool</option>
<option value="Undecided">Undecided</option>
<option value="Sad">Sad</option>
<option value="Crying">Crying</option>
</select>
<span className="help-block">{ this.getErrorMessageOf("mood") }</span>
</div>
<div className={ this.getErrorMessageOf("acceptConditions") ? "has-error" : "" }>
<div className="checkbox">
<label>
<input
type="checkbox"
name="acceptConditions"
ref="acceptConditions"
value={ this.getValueOf("acceptConditions") }
onChange={ this.handleChange.bind(this) }
required
/>
I'll behave nicely. { this.getErrorMessageOf("acceptConditions") }
</label>
</div>
</div>
<input type="submit" className="btn btn-success" value="Sign up"/>
</div>
</div>
<h2>Data</h2>
<pre>{ JSON.stringify(this.state.data, 2, 2) }</pre>
</form>
</div>
</div>
);
}
}
ReactDOM.render(<MyForm />, document.getElementById("root"))
</script>
</body>
</html>