form-wizard.js
4.39 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
jQuery(function($) {
$('[data-rel=tooltip]').tooltip();
$(".select2").css('width','200px').select2({allowClear:true})
.on('change', function(){
$(this).closest('form').validate().element($(this));
});
var $validation = false;
$('#fuelux-wizard-container')
.ace_wizard({
//step: 2 //optional argument. wizard will jump to step "2" at first
//buttons: '.wizard-actions:eq(0)'
})
.on('actionclicked.fu.wizard' , function(e, info){
if(info.step == 1 && $validation) {
if(!$('#validation-form').valid()) e.preventDefault();
}
})
.on('finished.fu.wizard', function(e) {
bootbox.dialog({
message: "Thank you! Your information was successfully saved!",
buttons: {
"success" : {
"label" : "OK",
"className" : "btn-sm btn-primary"
}
}
});
}).on('stepclick.fu.wizard', function(e){
//e.preventDefault();//this will prevent clicking and selecting steps
});
//jump to a step
/**
var wizard = $('#fuelux-wizard-container').data('fu.wizard')
wizard.currentStep = 3;
wizard.setState();
*/
//determine selected step
//wizard.selectedItem().step
//hide or show the other form which requires validation
//this is for demo only, you usullay want just one form in your application
$('#skip-validation').removeAttr('checked').on('click', function(){
$validation = this.checked;
if(this.checked) {
$('#sample-form').hide();
$('#validation-form').removeClass('hide');
}
else {
$('#validation-form').addClass('hide');
$('#sample-form').show();
}
})
//documentation : http://docs.jquery.com/Plugins/Validation/validate
$.mask.definitions['~']='[+-]';
$('#phone').mask('(999) 999-9999');
jQuery.validator.addMethod("phone", function (value, element) {
return this.optional(element) || /^\(\d{3}\) \d{3}\-\d{4}( x\d{1,6})?$/.test(value);
}, "Enter a valid phone number.");
$('#validation-form').validate({
errorElement: 'div',
errorClass: 'help-block',
focusInvalid: false,
ignore: "",
rules: {
email: {
required: true,
email:true
},
password: {
required: true,
minlength: 5
},
password2: {
required: true,
minlength: 5,
equalTo: "#password"
},
name: {
required: true
},
phone: {
required: true,
phone: 'required'
},
url: {
required: true,
url: true
},
comment: {
required: true
},
state: {
required: true
},
platform: {
required: true
},
subscription: {
required: true
},
gender: {
required: true,
},
agree: {
required: true,
}
},
messages: {
email: {
required: "Please provide a valid email.",
email: "Please provide a valid email."
},
password: {
required: "Please specify a password.",
minlength: "Please specify a secure password."
},
state: "Please choose state",
subscription: "Please choose at least one option",
gender: "Please choose gender",
agree: "Please accept our policy"
},
highlight: function (e) {
$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
},
success: function (e) {
$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
$(e).remove();
},
errorPlacement: function (error, element) {
if(element.is('input[type=checkbox]') || element.is('input[type=radio]')) {
var controls = element.closest('div[class*="col-"]');
if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
}
else if(element.is('.select2')) {
error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
}
else if(element.is('.chosen-select')) {
error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
}
else error.insertAfter(element.parent());
},
submitHandler: function (form) {
},
invalidHandler: function (form) {
}
});
$('#modal-wizard-container').ace_wizard();
$('#modal-wizard .wizard-actions .btn[data-dismiss=modal]').removeAttr('disabled');
/**
$('#date').datepicker({autoclose:true}).on('changeDate', function(ev) {
$(this).closest('form').validate().element($(this));
});
$('#mychosen').chosen().on('change', function(ev) {
$(this).closest('form').validate().element($(this));
});
*/
$(document).one('ajaxloadstart.page', function(e) {
//in ajax mode, remove remaining elements before leaving page
$('[class*=select2]').remove();
});
})