-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.html
174 lines (155 loc) · 5.23 KB
/
index.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>better-form-validation demo</title>
<!--[if IE]>
<script src="bower_components/better-dom/dist/better-dom-legacy.js"></script>
<![endif]-->
<style type="text/css">
body {
line-height: 1.5;
font-family: "Trebuchet MS", "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", sans-serif;
}
label { display: block; }
input, textarea, button {
font-size: 1em;
}
input[type=text], input[type=email], input[type=password], textarea {
border: 1px solid #333;
width: 100%;
margin: 0;
padding: 0.25em;
background: #F5F5F5;
}
form {
width: 300px;
}
#custom_form input {
-webkit-transition: -webkit-transform 0.3s ease-in-out;
transition: transform 0.3s ease-in-out;
}
#custom_form input[aria-invalid=true] {
-webkit-transform: rotate(-3deg);
transform: rotate(-3deg);
}
/* reset user agent styles */
:invalid {
outline: inherit;
box-shadow: inherit;
}
input[aria-invalid]::-ms-clear,
input[aria-invalid]::-ms-reveal {
display: none;
}
/* change background depending on value validity */
input[aria-invalid=false] {
background-color: #42B300;
}
input[aria-invalid=true] {
background-color: #FF5300;
}
/*input[aria-invalid] {
background-size: auto 80%;
background-position: right center;
background-repeat: no-repeat;
}
input[aria-invalid=false] {
background-image: url(valid-icon.svg);
}
input[aria-invalid=true] {
background-image: url(invalid-icon.svg);
}
input[aria-invalid][type=checkbox],
input[aria-invalid][type=radio] {
background: none;
}*/
</style>
</head>
<body>
<h2>Default form validation</h2>
<form>
<p>
<label>Your email<br>
<input type="email" placeholder="[email protected]" name="email" required>
</label>
</p>
<p>
<label>Your password<br>
<input type="password" placeholder="secret" name="password" pattern="[a-z]+" title="оnly letters, please">
</label>
</p>
<p>
<label>Your comment<br>
<textarea placeholder="say what you think..." name="comment" rows="3" maxlength="10"></textarea>
</label>
</p>
<p>
Select gender:
<label><input type="radio" name="gender" value="male" required>Male</label>
<label><input type="radio" name="gender" value="female" required>Female</label>
</p>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
<hr>
<h2>Summary validation example</h2>
<form id="custom_form">
<ul id="custom_form_errors" style="color:red"></ul>
<p>
<label>Your email<br>
<input type="email" placeholder="[email protected]" name="email" required>
</label>
</p>
<p>
<label>Your password<br>
<input type="password" placeholder="secret" name="password" required>
</label>
</p>
<p>
<label>Reply your password<br>
<input type="password" placeholder="secret" name="reply_password" required>
</label>
</p>
<p>
<label>
<input type="checkbox" name="accept" value="yes" required>
I accept terms
</label>
</p>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</form>
<script src="bower_components/better-dom/dist/better-dom.js"></script>
<script src="bower_components/better-i18n-plugin/dist/better-i18n-plugin.js"></script>
<script src="bower_components/better-popover-plugin/dist/better-popover-plugin.js"></script>
<script src="build/better-form-validation.js"></script>
<script src="i18n/better-form-validation.ru.js"></script>
<script type="text/javascript">
DOM.extend("body", function() {
var form = DOM.find("#custom_form"),
password = form.find("[name=password]"),
replyPassword = form.find("[name=reply_password]"),
button = DOM.find("[type=submit]"),
customErrors = DOM.find("#custom_form_errors");
replyPassword.validity(function() {
if (password.get() !== replyPassword.get()) {
return "passwords should match";
}
});
form.on("validity:fail", [1, "target"], function(errors, target) {
if (target !== form) return false;
customErrors.set("");
Object.keys(errors).forEach(function(field) {
var li = DOM.create("li>`{0}: `", [field]),
error = errors[field][0];
if (error) {
customErrors.append(li.append(DOM.__(error).toString()));
}
});
});
});
</script>
</body>
</html>