-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
328 lines (307 loc) · 11 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Form Validate</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" src="jquery.formvalidate.js"></script>
<script type="text/javascript" src="localization/de.js"></script>
<script type="text/javascript" src="localization/es.js"></script>
<script type="text/javascript" src="localization/pirate.js"></script>
<style type="text/css">
body {
background-color: #333;
padding-right: 0px;
padding-left: 0px;
}
form {
position: relative;
margin: 15px;
padding: 5px 15px 5px 15px;
background-color: #fff;
border: 1px solid #ddd;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
legend a {
float: right;
margin-top: 6px;
}
pre {
display: none;
}
#languages {
text-align: right;
margin: 0px 15px 15px 15px;
}
#languages a {
margin: 0px 5px;
font-size: 11px;
color: #999;
}
#languages a.current {
color: #bbb;
}
</style>
</head>
<body>
<div class="row-fluid">
<div class="span12">
<form id="form-1" method="post" action="" class="form-horizontal">
<fieldset>
<legend>Basic Form <a href="#example-1" class="btn btn-mini"><i class="icon-eye-close"></i> Code</a></legend>
<div class="control-group">
<label for="required" class="control-label">Anything</label>
<div class="controls">
<input type="text" id="required" name="required" data-trim data-min-length="2" title="Anything" class="required" maxlength="128">
</div>
</div>
<div class="control-group">
<label for="optional" class="control-label">Optional</label>
<div class="controls">
<input type="text" id="optional" name="optional" title="Optional" maxlength="128">
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" class="btn btn-small btn-primary" id="submit-1" value="Submit">
</div>
</div>
<pre id="example-1">// Validate on form submission
$('#form-1').submit(function(e) {
e.preventDefault();
$(this).formvalidate({
failureMessages: true,
successMessages: true,
messageFailureClass: 'label label-important',
messageSuccessClass: 'label label-success',
onSuccess: function(form) {
alert('Form #1 is valid!');
}
});
});</pre>
</fieldset>
</form>
<form id="form-2" method="post" action="" class="form-horizontal">
<fieldset>
<legend>Advanced Form <a href="#example-2" class="btn btn-mini"><i class="icon-eye-close"></i> Code</a></legend>
<div class="control-group">
<label class="control-label" for="name">Name</label>
<div class="controls">
<input type="text" id="name" name="name" title="Name" data-trim data-min-chars="3" data-is-not="vic bob tom sam" class="required" maxlength="128">
</div>
</div>
<div class="control-group">
<label class="control-label" for="age">Age</label>
<div class="controls">
<input type="text" id="age" name="age" title="Age" data-int data-between-numeric="1 101" maxlength="128">
</div>
</div>
<div class="control-group">
<label class="control-label" for="birth_date">Birth Date</label>
<div class="controls">
<input type="text" id="birth_date" name="birth_date" title="Birth Date" data-date="YYYY-MM-DD" maxlength="128" placeholder="YYYY-MM-DD">
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">Email</label>
<div class="controls">
<input type="text" id="email" name="email" title="Email" data-min-chars="5" data-email class="required" maxlength="128">
</div>
</div>
<div class="control-group">
<label class="control-label" for="continent">Continent</label>
<div class="controls">
<select id="continent" name="continent" title="Continent" class="required">
<option value="">— Please Select —</option>
<option value="na">North America</option>
<option value="sa">South America</option>
<option value="an">Antarctica</option>
<option value="af">Africa</option>
<option value="eu">Europe</option>
<option value="as">Asia</option>
<option value="au">Australia</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Are You Cool?</label>
<div class="controls">
<label class="radio inline"><input type="radio" name="cool" value="Y" id="cool-yes" class="required" title="Are you cool?"> Yes</label>
<label class="radio inline"><input type="radio" name="cool" value="N" id="cool-no"> No</label>
</div>
</div>
<div class="control-group">
<label class="control-label" for="why_cool">Why So Cool?</label>
<div class="controls">
<textarea id="why_cool" name="why_cool" data-trim data-min-length="4" data-max-length="512" data-required-if="cool-yes" title="Why So Cool?" cols="64" rows="8"></textarea>
</div>
</div>
<div class="control-group">
<label class="control-label">What 2 colors do you like?</label>
<div class="controls">
<select multiple="multiple" id="colors" name="colors[]" title="Colors" data-num-options="2" class="required">
<option value="red">Red</option>
<option value="orange">Orange</option>
<option value="yellow">Yellow</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="purple">Purple</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">What Do You Like?</label>
<div class="controls">
<label class="checkbox inline"><input type="checkbox" name="like[]" value="ci" title="What do you like?" class="required"> CodeIgniter</label>
<label class="checkbox inline"><input type="checkbox" name="like[]" value="fuel" data-min-options="2" data-max-options="4"> Fuel</label>
<label class="checkbox inline"><input type="checkbox" name="like[]" value="kohana"> Kohana</label>
<label class="checkbox inline"><input type="checkbox" name="like[]" value="laravel"> Laravel</label>
<label class="checkbox inline"><input type="checkbox" name="like[]" value="zend"> Zend</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="submit" class="btn btn-small btn-primary" id="submit-2" value="Submit">
</div>
</div>
<pre id="example-2">$('#submit-2').click(function(e) {
e.preventDefault();
// From the anchor element find the closest form element
$(this).closest('form').formvalidate({
failureMessages: true,
successMessages: true,
messageFailureClass: 'label label-important',
messageSuccessClass: 'label label-success',
onSuccess: function(form) {
alert('Form #2 is valid!');
},
localization: {
en: {
success: {
name: 'Good, you know your name.',
age: 'Ahh, {1}, a wise age.',
birth_date: 'The year of the tiger!',
email: 'We promise not to stalk you.',
continent: function(title, value, name, input) {
var text = $(':input[name="' + name + '"] option[value="' + value + '"]').text();
return text + ', really? Me too!';
},
'colors[]': 'O, wow good choices!',
why_cool: 'Ya, u got it!',
'like[]': 'Those are my favorite frameworks too.!'
},
failure: {
email: function(title, value, name, input) {
return 'There is no way that email ' + value + ' is valid.';
}
}
}
}
});
});</pre>
</fieldset>
</form>
<div id="languages">
<a href="javascript:void(0);" data-language="de">Deutsch</a>
<a href="javascript:void(0);" data-language="en" class="current">English</a>
<a href="javascript:void(0);" data-language="es">Español</a>
<a href="javascript:void(0);" data-language="pirate">Pirate</a>
</div>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
// Validate on form submission
$('#form-1').submit(function(e) {
e.preventDefault();
$(this).formvalidate({
failureMessages: true,
successMessages: true,
messageFailureClass: 'label label-important',
messageSuccessClass: 'label label-success',
onSuccess: function(O) {
alert('Form #1 is valid!');
}
});
});
// Validate when the submit button is clicked
$('#submit-2').click(function(e) {
e.preventDefault();
// From the anchor element find the closest form element
$(this).closest('form').formvalidate({
failureMessages: true,
successMessages: true,
messageFailureClass: 'label label-important',
messageSuccessClass: 'label label-success',
onSuccess: function(form) {
alert('Form #2 is valid!');
},
validations: {
isNot: function(input, params) {
return $.inArray(input.toLowerCase(), params);
}
},
localization: {
en: {
success: {
name: 'Good, you know your name.',
age: 'Ahh, {1}, a wise age.',
birth_date: function() {
var animals = ['rat', 'ox', 'tiger', 'rabbit', 'dragon', 'snake', 'horse', 'sheep', 'monkey', 'rooster', 'dog', 'pig']
var animal = animals[Math.floor(Math.random()*animals.length)];
return 'The year of the ' + animal + '!';
},
email: 'We promise not to stalk you.',
continent: function(title, value, name, input) {
var text = $(':input[name="' + name + '"] option[value="' + value + '"]').text();
return text + ', really? Me too!';
},
'colors[]': 'O, wow good choices!',
why_cool: 'Ya, u got it!',
'like[]': 'Those are my favorite frameworks too.!'
},
failure: {
email: function(title, value, name, input) {
return 'There is no way that email ' + value + ' is valid.';
},
isNot: function(title, value, name, input) {
return 'That name is not original enough.';
}
}
}
}
});
});
// Toggle "Why So Cool?"
(function () {
var cool = $('input[name="cool"]');
var why = $('#why_cool').closest('.control-group');
// Toggle "Why So Cool?" question
var toggle = function toggle() {;
$(cool).filter(':checked').val() === 'Y' ? $(why).show() : $(why).hide();
return toggle;
}();
// Run toggle function on change
$(document).on('change', $(cool), function() {
toggle();
});
})();
// Toggle code
$('legend a').click(function(e) {
e.preventDefault();
$( $(this).attr('href') ).toggle();
});
// Toggle language
$('#languages a').click(function(e) {
e.preventDefault();
$.extend(true, jQuery.fn.formvalidate.options.language = $(this).data('language'));
$(this).siblings().removeClass('current').end().addClass('current');
});
});
</script>
</body>
</html>