form-wizard.js
3.06 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
'use strict';
$(document).ready(function() {
// $('#date,#datejoin').bootstrapMaterialDatePicker({
// time: false,
// clearButton: true
// });
// $("#example-date-inputS").bootstrapMaterialDatePicker({
// time: false,
// clearButton: true
// });
$("#basic-forms").steps({
headerTag: "h3",
bodyTag: "fieldset",
transitionEffect: "slideLeft",
autoFocus: true
});
$("#example-advanced-form").steps({
headerTag: "h3",
bodyTag: "fieldset",
transitionEffect: "slideLeft",
autoFocus: true
});
$("#design-wizard").steps({
headerTag: "h3",
bodyTag: "fieldset",
transitionEffect: "slideLeft",
autoFocus: true
});
var form = $("#verticle-wizard").show();
form.steps({
headerTag: "h3",
bodyTag: "fieldset",
transitionEffect: "slide",
stepsOrientation: "vertical",
autoFocus: true,
onStepChanging: function(event, currentIndex, newIndex) {
// Allways allow previous action even if the current form is not valid!
if (currentIndex > newIndex) {
return true;
}
// Forbid next action on "Warning" step if the user is to young
if (newIndex === 3 && Number($("#age-2").val()) < 18) {
return false;
}
// Needed in some cases if the user went back (clean up)
if (currentIndex < newIndex) {
// To remove error styles
form.find(".body:eq(" + newIndex + ") label.error").remove();
form.find(".body:eq(" + newIndex + ") .error").removeClass("error");
}
form.validate().settings.ignore = ":disabled,:hidden";
return form.valid();
},
onStepChanged: function(event, currentIndex, priorIndex) {
// Used to skip the "Warning" step if the user is old enough.
if (currentIndex === 2 && Number($("#age-2").val()) >= 18) {
form.steps("next");
}
// Used to skip the "Warning" step if the user is old enough and wants to the previous step.
if (currentIndex === 2 && priorIndex === 3) {
form.steps("previous");
}
},
onFinishing: function(event, currentIndex) {
form.validate().settings.ignore = ":disabled";
return form.valid();
},
onFinished: function(event, currentIndex) {
var form = $(this);
// Submit form input
form.submit();
}
}).validate({
errorPlacement: function errorPlacement(error, element) {
element.before(error);
},
rules: {
confirm: {
equalTo: "#password-2"
}
}
});
});