-
-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathvalidation.html
More file actions
411 lines (352 loc) · 14.6 KB
/
validation.html
File metadata and controls
411 lines (352 loc) · 14.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
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery SmartWizard v7 — Form Validation Demo</title>
<meta name="description" content="jQuery SmartWizard v7 demo — Bootstrap form validation on each wizard step">
<link href="./css/demo.css" rel="stylesheet" type="text/css" />
<!-- Animate.css for CSS animation support -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" rel="stylesheet" />
<!-- Include SmartWizard CSS -->
<link href="../dist/css/smartwizard.css" rel="stylesheet" type="text/css" />
<!-- Include SmartWizard Themes -->
<link href="../dist/css/themes/basic.css" rel="stylesheet" type="text/css" />
<link href="../dist/css/themes/arrows.css" rel="stylesheet" type="text/css" />
<link href="../dist/css/themes/pills.css" rel="stylesheet" type="text/css" />
<link href="../dist/css/themes/glow.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- Header -->
<header class="demo-header">
<h1>jQuery SmartWizard 7 — Form Validation Demo</h1>
<div class="header-right" id="demo-nav"></div>
<div class="header-right">
<button class="header-btn" id="toggle-dark"> ⚡Auto</button>
</div>
</header>
<!-- Controls bar -->
<div class="demo-controls">
<div class="demo-control-wrapper">
<div class="control-group">
<label class="control-label" for="theme-select">Theme:</label>
<select class="ctrl-select" id="theme-select">
</select>
</div>
<div class="ctrl-divider"></div>
<div class="control-group">
<label class="control-label" for="transition-select">Animation:</label>
<select class="ctrl-select" id="transition-select">
</select>
</div>
<div class="ctrl-divider"></div>
<div class="control-group">
<span class="control-label">Color:</span>
<div class="btn-group" id="color-list">
</div>
</div>
</div>
<div class="demo-control-wrapper">
<div class="control-group">
<label class="control-label" for="toolbar-select">Toolbar:</label>
<select class="ctrl-select" id="toolbar-select">
<option value="both" selected>Both</option>
<option value="top">Top</option>
<option value="bottom">Bottom</option>
<option value="none">None</option>
</select>
</div>
<div class="ctrl-divider"></div>
<div class="control-group">
<label class="control-label">External Controls:</label>
<div class="btn-group">
<button class="btn" id="btn-prev">← Prev</button>
<button class="btn" id="btn-next">Next →</button>
<button class="btn" id="btn-reset">↺ Reset</button>
</div>
</div>
<div class="ctrl-divider"></div>
<div class="control-group">
<label class="control-label" for="toolbar-select">Progress:</label>
<div>
<span class="step-info-pill">Step <span id="sw-cur">1</span> of <span id="sw-total">4</span></span>
</div>
</div>
</div>
</div>
<!-- Wizard -->
<div class="demo-body">
<div class="wizard-card">
<!-- SmartWizard -->
<div id="smartwizard">
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#step-1">
<span class="badge">1</span>
Customer Details
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#step-2">
<span class="badge">2</span>
Products Details
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#step-3">
<span class="badge">3</span>
Shipping Details
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#step-4">
<span class="badge">4</span>
Confirm Order
</a>
</li>
</ul>
<div class="tab-content sw-form-wrapper">
<div id="step-1" class="tab-pane" role="tabpanel" aria-labelledby="step-1">
<form id="form-1" action="#" method="post">
<p>
<label for="first-name">First name</label>
<input type="text" id="first-name" value="" required>
</p>
<p>
<label for="last-name">Last name</label>
<input type="text" id="last-name" value="" required>
</p>
<p>
<label for="age">Age</label>
<input type="number" name="age" required id="age" min="21" max="65" />
</p>
</form>
</div>
<div id="step-2" class="tab-pane" role="tabpanel" aria-labelledby="step-2">
<form id="form-2" action="#" method="post">
<p>
<label for="sel-products">Product</label>
<select class="form-select" id="sel-products" multiple required>
<option value="Apple iPhone 13">Apple iPhone 13</option>
<option value="Apple iPhone 12">Apple iPhone 12</option>
<option value="Samsung Galaxy S10">Samsung Galaxy S10</option>
<option value="Motorola G5">Motorola G5</option>
</select>
</p>
</form>
</div>
<div id="step-3" class="tab-pane" role="tabpanel" aria-labelledby="step-3">
<form id="form-3" action="#" method="post">
<p>
<label for="address">Address</label>
<input type="text" id="address" placeholder="1234 Main St" required>
</p>
<p>
<label for="state">State</label>
<select id="state" required>
<option selected disabled value="">Choose...</option>
<option>State 1</option>
<option>State 2</option>
<option>State 3</option>
</select>
</p>
<p>
<label for="zip">Zip</label>
<input type="text" id="zip" required>
</p>
</form>
</div>
<div id="step-4" class="tab-pane" role="tabpanel" aria-labelledby="step-4">
<form id="form-4" class="row row-cols-1 needs-validation" style="padding:0 1.5rem" novalidate>
<div class="col">
<div style="margin-bottom:.75rem;color:var(--sw-text-muted,#888)">Please confirm your order details
</div>
<div id="order-details"></div>
<h4 style="margin-top:1rem">Payment</h4>
<hr style="margin:.5rem 0">
<div class="row gy-3">
<div class="col-md-3">
<label for="cc-name" class="form-label">Name on card</label>
<input type="text" class="form-control" id="cc-name" value="My Name" placeholder="" required>
<small style="color:var(--sw-text-muted,#888)">Full name as displayed on card</small>
<div class="invalid-feedback">Name on card is required</div>
</div>
<div class="col-md-3">
<label for="cc-number" class="form-label">Credit card number</label>
<input type="text" class="form-control" id="cc-number" value="54545454545454" placeholder=""
required>
<div class="invalid-feedback">Credit card number is required</div>
</div>
<div class="col-md-3">
<label for="cc-expiration" class="form-label">Expiration</label>
<input type="text" class="form-control" id="cc-expiration" value="1/28" placeholder="" required>
<div class="invalid-feedback">Expiration date required</div>
</div>
<div class="col-md-3">
<label for="cc-cvv" class="form-label">CVV</label>
<input type="text" class="form-control" id="cc-cvv" value="123" placeholder="" required>
<div class="invalid-feedback">Security code required</div>
</div>
<div class="col">
<input type="checkbox" class="form-check-input" id="save-info" required>
<label class="form-check-label" for="save-info">I agree to the terms and conditions</label>
</div>
<small style="color:var(--sw-text-muted,#888)">This is an example page, do not enter any real
data.</small>
</div>
</div>
</form>
</div>
</div>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width: 25%" aria-valuenow="25" aria-valuemin="0"
aria-valuemax="100"></div>
</div>
</div>
</div>
</div>
<!-- Confirm Modal (using native dialog for no Bootstrap dep) -->
<dialog id="confirmModal"
style="border:none;border-radius:1rem;padding:2rem;max-width:420px;box-shadow:0 8px 40px rgba(0,0,0,.2);background:var(--sw-bg-surface,#fff);color:var(--sw-text-main,#111)">
<h3 style="margin:0 0 .5rem">Order Placed 🎉</h3>
<p>Congratulations! Your order is placed.</p>
<div style="text-align:right;margin-top:1rem">
<button class="btn btn-primary" onclick="closeModal()">Ok, close and reset</button>
</div>
</dialog>
<script src="./js/demo.js"></script>
<!-- jQuery -->
<script src="https://code.jquery.com/jquery-4.0.0.min.js"
integrity="sha256-OaVG6prZf4v69dPg6PhVattBXkcOWQB62pdZ3ORyrao=" crossorigin="anonymous"></script>
<!-- SmartWizard -->
<script src="../dist/js/jquery.smartWizard.js"></script>
<script src="./js/wizard-settings.js"></script>
<!-- Page-specific SmartWizard init -->
<script>
const confirmDialog = document.getElementById('confirmModal');
function onCancel() {
wizardElement.smartWizard("reset");
document.getElementById("form-1").reset();
document.getElementById("form-2").reset();
document.getElementById("form-3").reset();
document.getElementById("form-4").reset();
}
function onConfirm() {
let form = document.getElementById('form-4');
const message = document.querySelectorAll('.form-message');
if (form) {
if (!form.checkValidity()) {
form.classList.add('was-validated');
wizardElement.smartWizard("setState", [3], 'error');
wizardElement.smartWizard('fixHeight');
message.forEach(element => {
element.textContent = "Please fill all the fields";
});
return false;
}
wizardElement.smartWizard("unsetState", [3], 'error');
confirmDialog.showModal();
}
}
function closeModal() {
wizardElement.smartWizard("reset");
document.getElementById("form-1").reset();
document.getElementById("form-2").reset();
document.getElementById("form-3").reset();
document.getElementById("form-4").reset();
confirmDialog.close();
}
function showConfirm() {
const name = $('#first-name').val() + ' ' + $('#last-name').val();
const products = $('#sel-products').val();
const shipping = $('#address').val() + ' ' + $('#state').val() + ' ' + $('#zip').val();
let html = `
<div class="row">
<div class="col">
<h4>Customer Details</h4>
<hr style="margin:.25rem 0">
<div style="margin:.5rem 0"><label style="color:var(--sw-text-muted,#888)">Name</label> ${name}</div>
</div>
<div class="col">
<h4>Shipping</h4>
<hr style="margin:.25rem 0">
<div style="margin:.5rem 0">${shipping}</div>
</div>
</div>
<h4 style="margin-top:1rem">Products</h4>
<hr style="margin:.25rem 0">
<div style="margin:.5rem 0">${products}</div>
`;
$("#order-details").html(html);
wizardElement.smartWizard('fixHeight');
}
$(function () {
wizardElement = $('#smartwizard');
activeTheme = 'arrows';
activeTransition = 'none';
activeColor = '';
initWizardControls(wizardElement);
initTheme();
function validateStep(stepIndex) {
let form = document.getElementById('form-' + (stepIndex + 1));
const message = document.querySelectorAll('.form-message');
message.forEach(element => {
element.textContent = "";
});
if (form) {
if (!form.checkValidity()) {
form.classList.add('was-validated');
wizardElement.smartWizard("setState", [stepIndex], 'error');
wizardElement.smartWizard('fixHeight');
message.forEach(element => {
element.textContent = "Please fill all the fields";
});
return false;
}
wizardElement.smartWizard("unsetState", [stepIndex], 'error');
}
return true;
}
wizardElement.on("shown.sw", function (e, args) {
const stepDirection = args.stepDirection;
const stepPosition = args.stepPosition;
const stepIndex = args.stepIndex;
// Enable confirm button on last step
if (stepPosition == 'last') {
$('.btn-finish').removeClass('disabled').removeAttr('disabled');
} else {
$('.btn-finish').addClass('disabled').attr('disabled', 'disabled');
}
});
// Step leave event
wizardElement.on("leave.sw", function (e, args) {
const stepDirection = args.stepDirection;
const stepPosition = args.stepPosition;
const stepIndex = args.stepIndex;
// Only validate on the forward movement
if (stepDirection == 'forward') {
const output = document.querySelector("#log-" + stepIndex);
return validateStep(stepIndex);
}
return true;
});
// Init SmartWizard
wizardElement.smartWizard({
theme: activeTheme,
displayMode: displayMode,
transition: {
effect: activeTransition,
speed: 400,
},
toolbar: {
position: 'both',
extraElements: `
<div class="form-message" style="color: red;font-size:18px;position:absolute;left:30px"></div>
<button class="sw-btn sw-btn-primary btn-finish" id="btnFinish" disabled onclick="onConfirm()">Complete Order</button>
<button class="sw-btn sw-btn-secondary" id="btnCancel" onclick="onCancel()">Cancel</button>`
},
});
});
</script>
</body>
</html>