artfully_ose 1.2.0.pre.24 → 1.2.0.pre.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +9 -9
- data/app/assets/fonts/FontAwesome.otf +0 -0
- data/app/assets/fonts/fontawesome-webfont.eot +0 -0
- data/app/assets/fonts/fontawesome-webfont.svg +504 -0
- data/app/assets/fonts/fontawesome-webfont.ttf +0 -0
- data/app/assets/fonts/fontawesome-webfont.woff +0 -0
- data/app/assets/javascripts/application.js +5 -0
- data/app/assets/javascripts/custom/people.js +68 -5
- data/app/assets/javascripts/sales-console.js +153 -0
- data/app/assets/javascripts/store/jquery.validate.additional-methods.js +476 -159
- data/app/assets/javascripts/store/jquery.validate.js +449 -406
- data/app/assets/stylesheets/application.sass +49 -0
- data/app/assets/stylesheets/font-awesome.css.scss +1566 -0
- data/app/concerns/cart_finder.rb +5 -0
- data/app/controllers/console_sales_controller.rb +182 -0
- data/app/controllers/events_controller.rb +1 -1
- data/app/controllers/events_pass_types_controller.rb +10 -0
- data/app/controllers/memberships_controller.rb +3 -3
- data/app/controllers/people_controller.rb +2 -1
- data/app/controllers/sales_controller.rb +51 -13
- data/app/controllers/shows_controller.rb +2 -2
- data/app/controllers/store/orders_controller.rb +0 -9
- data/app/helpers/artfully_ose_helper.rb +4 -2
- data/app/helpers/sales_helper.rb +29 -0
- data/app/models/cart.rb +6 -1
- data/app/models/checkout.rb +20 -13
- data/app/models/comp.rb +13 -16
- data/app/models/console_sale.rb +30 -0
- data/app/models/database_views/item_view.rb +3 -0
- data/app/models/job/checkout_processor.rb +10 -5
- data/app/models/kits/mailchimp_kit.rb +2 -1
- data/app/models/kits/passes_kit.rb +1 -1
- data/app/models/kits/scannable_tickets_kit.rb +3 -4
- data/app/models/membership.rb +18 -3
- data/app/models/membership_change.rb +1 -1
- data/app/models/membership_type.rb +2 -3
- data/app/models/order.rb +20 -17
- data/app/models/order_handler.rb +21 -0
- data/app/models/orders/comp_order.rb +1 -1
- data/app/models/parsed_row.rb +45 -2
- data/app/models/pass.rb +13 -0
- data/app/models/pass_type.rb +16 -0
- data/app/models/payment.rb +17 -0
- data/app/models/payments/cash_payment.rb +3 -1
- data/app/models/payments/check_payment.rb +33 -0
- data/app/models/payments/comp_payment.rb +3 -1
- data/app/models/payments/credit_card_payment.rb +8 -18
- data/app/models/person.rb +27 -3
- data/app/models/sale.rb +13 -10
- data/app/models/ticket.rb +1 -1
- data/app/views/console_sales/_aloha.html.haml +26 -0
- data/app/views/console_sales/_cart.html.haml +60 -0
- data/app/views/console_sales/_payment.html.haml +111 -0
- data/app/views/console_sales/_shows.html.haml +24 -0
- data/app/views/console_sales/new.html.haml +143 -0
- data/app/views/events/_day_date_show.html.haml +2 -2
- data/app/views/events/_ticket_type_fields.html.haml +1 -1
- data/app/views/events_pass_types/_form.html.haml +1 -1
- data/app/views/events_pass_types/index.html.haml +2 -1
- data/app/views/exchanges/new.html.haml +1 -1
- data/app/views/imports/people/_new.html.haml +12 -0
- data/app/views/kits/_list.html.haml +2 -1
- data/app/views/layouts/_menu.html.haml +0 -3
- data/app/views/membership_comps/create.html.haml +3 -1
- data/app/views/membership_types/_form.html.haml +0 -1
- data/app/views/orders/_item_table.haml +5 -3
- data/app/views/passes/index.html.haml +2 -2
- data/app/views/people/_edit_modal.html.haml +7 -0
- data/app/views/people/_work_with_menu.html.haml +4 -1
- data/app/views/people/show.html.haml +13 -4
- data/app/views/refunds/new.html.haml +1 -1
- data/app/views/sales/_boxoffice.html.haml +141 -0
- data/app/views/sales/_doorlist.html.haml +79 -0
- data/app/views/sales/new.html.haml +33 -125
- data/app/views/searches/show.html.haml +1 -1
- data/app/views/segments/show.html.haml +1 -1
- data/app/views/shows/_ticket_table.html.haml +1 -1
- data/app/views/shows/_work_with.html.haml +1 -1
- data/app/views/shows/index.html.haml +5 -6
- data/app/views/shows/show.html.haml +2 -2
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/paperclip.rb +16 -0
- data/config/routes.rb +10 -1
- data/db/migrate/20140507184646_add_bday_attributes_to_person.rb +7 -0
- data/db/migrate/20140507201048_add_check_number_to_orders.rb +5 -0
- data/db/migrate/20140619194127_add_do_not_call_to_people.artfully_ose_engine.rb +5 -0
- data/db/migrate/20140623160543_add_index_to_items.rb +7 -0
- data/lib/artfully_ose/engine.rb +5 -4
- data/lib/artfully_ose/version.rb +1 -1
- data/spec/factories/person_factories.rb +3 -0
- metadata +43 -20
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
* jQuery Validation Plugin 1.
|
1
|
+
/*!
|
2
|
+
* jQuery Validation Plugin 1.11.1
|
3
3
|
*
|
4
4
|
* http://bassistance.de/jquery-plugins/jquery-plugin-validation/
|
5
5
|
* http://docs.jquery.com/Plugins/Validation
|
6
6
|
*
|
7
|
-
* Copyright
|
8
|
-
*
|
9
|
-
* Dual licensed under the MIT and GPL licenses:
|
7
|
+
* Copyright 2013 Jörn Zaefferer
|
8
|
+
* Released under the MIT license:
|
10
9
|
* http://www.opensource.org/licenses/mit-license.php
|
11
|
-
* http://www.gnu.org/licenses/gpl.html
|
12
10
|
*/
|
13
11
|
|
14
12
|
(function($) {
|
@@ -18,53 +16,57 @@ $.extend($.fn, {
|
|
18
16
|
validate: function( options ) {
|
19
17
|
|
20
18
|
// if nothing is selected, return nothing; can't chain anyway
|
21
|
-
if (!this.length) {
|
22
|
-
options && options.debug && window.console
|
19
|
+
if ( !this.length ) {
|
20
|
+
if ( options && options.debug && window.console ) {
|
21
|
+
console.warn( "Nothing selected, can't validate, returning nothing." );
|
22
|
+
}
|
23
23
|
return;
|
24
24
|
}
|
25
25
|
|
26
26
|
// check if a validator for this form was already created
|
27
|
-
var validator = $.data(this[0],
|
27
|
+
var validator = $.data( this[0], "validator" );
|
28
28
|
if ( validator ) {
|
29
29
|
return validator;
|
30
30
|
}
|
31
31
|
|
32
32
|
// Add novalidate tag if HTML5.
|
33
|
-
this.attr(
|
33
|
+
this.attr( "novalidate", "novalidate" );
|
34
34
|
|
35
35
|
validator = new $.validator( options, this[0] );
|
36
|
-
$.data(this[0],
|
36
|
+
$.data( this[0], "validator", validator );
|
37
37
|
|
38
38
|
if ( validator.settings.onsubmit ) {
|
39
39
|
|
40
|
-
|
40
|
+
this.validateDelegate( ":submit", "click", function( event ) {
|
41
|
+
if ( validator.settings.submitHandler ) {
|
42
|
+
validator.submitButton = event.target;
|
43
|
+
}
|
44
|
+
// allow suppressing validation by adding a cancel class to the submit button
|
45
|
+
if ( $(event.target).hasClass("cancel") ) {
|
46
|
+
validator.cancelSubmit = true;
|
47
|
+
}
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
49
|
+
// allow suppressing validation by adding the html5 formnovalidate attribute to the submit button
|
50
|
+
if ( $(event.target).attr("formnovalidate") !== undefined ) {
|
51
|
+
validator.cancelSubmit = true;
|
52
|
+
}
|
45
53
|
});
|
46
54
|
|
47
|
-
// when a submitHandler is used, capture the submitting button
|
48
|
-
if (validator.settings.submitHandler) {
|
49
|
-
inputsAndButtons.filter(":submit").click(function () {
|
50
|
-
validator.submitButton = this;
|
51
|
-
});
|
52
|
-
}
|
53
|
-
|
54
55
|
// validate the form on submit
|
55
56
|
this.submit( function( event ) {
|
56
|
-
if ( validator.settings.debug )
|
57
|
+
if ( validator.settings.debug ) {
|
57
58
|
// prevent form submit to be able to see console output
|
58
59
|
event.preventDefault();
|
59
|
-
|
60
|
+
}
|
60
61
|
function handle() {
|
62
|
+
var hidden;
|
61
63
|
if ( validator.settings.submitHandler ) {
|
62
|
-
if (validator.submitButton) {
|
64
|
+
if ( validator.submitButton ) {
|
63
65
|
// insert a hidden input as a replacement for the missing submit button
|
64
|
-
|
66
|
+
hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val( $(validator.submitButton).val() ).appendTo(validator.currentForm);
|
65
67
|
}
|
66
|
-
validator.settings.submitHandler.call( validator, validator.currentForm );
|
67
|
-
if (validator.submitButton) {
|
68
|
+
validator.settings.submitHandler.call( validator, validator.currentForm, event );
|
69
|
+
if ( validator.submitButton ) {
|
68
70
|
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
|
69
71
|
hidden.remove();
|
70
72
|
}
|
@@ -95,49 +97,52 @@ $.extend($.fn, {
|
|
95
97
|
},
|
96
98
|
// http://docs.jquery.com/Plugins/Validation/valid
|
97
99
|
valid: function() {
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
valid
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
100
|
+
if ( $(this[0]).is("form")) {
|
101
|
+
return this.validate().form();
|
102
|
+
} else {
|
103
|
+
var valid = true;
|
104
|
+
var validator = $(this[0].form).validate();
|
105
|
+
this.each(function() {
|
106
|
+
valid = valid && validator.element(this);
|
107
|
+
});
|
108
|
+
return valid;
|
109
|
+
}
|
110
|
+
},
|
109
111
|
// attributes: space seperated list of attributes to retrieve and remove
|
110
|
-
removeAttrs: function(attributes) {
|
112
|
+
removeAttrs: function( attributes ) {
|
111
113
|
var result = {},
|
112
114
|
$element = this;
|
113
|
-
$.each(attributes.split(/\s/), function(index, value) {
|
115
|
+
$.each(attributes.split(/\s/), function( index, value ) {
|
114
116
|
result[value] = $element.attr(value);
|
115
117
|
$element.removeAttr(value);
|
116
118
|
});
|
117
119
|
return result;
|
118
120
|
},
|
119
121
|
// http://docs.jquery.com/Plugins/Validation/rules
|
120
|
-
rules: function(command, argument) {
|
122
|
+
rules: function( command, argument ) {
|
121
123
|
var element = this[0];
|
122
124
|
|
123
|
-
if (command) {
|
124
|
-
var settings = $.data(element.form,
|
125
|
+
if ( command ) {
|
126
|
+
var settings = $.data(element.form, "validator").settings;
|
125
127
|
var staticRules = settings.rules;
|
126
128
|
var existingRules = $.validator.staticRules(element);
|
127
129
|
switch(command) {
|
128
130
|
case "add":
|
129
131
|
$.extend(existingRules, $.validator.normalizeRule(argument));
|
132
|
+
// remove messages from rules, but allow them to be set separetely
|
133
|
+
delete existingRules.messages;
|
130
134
|
staticRules[element.name] = existingRules;
|
131
|
-
if (argument.messages)
|
135
|
+
if ( argument.messages ) {
|
132
136
|
settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
|
137
|
+
}
|
133
138
|
break;
|
134
139
|
case "remove":
|
135
|
-
if (!argument) {
|
140
|
+
if ( !argument ) {
|
136
141
|
delete staticRules[element.name];
|
137
142
|
return existingRules;
|
138
143
|
}
|
139
144
|
var filtered = {};
|
140
|
-
$.each(argument.split(/\s/), function(index, method) {
|
145
|
+
$.each(argument.split(/\s/), function( index, method ) {
|
141
146
|
filtered[method] = existingRules[method];
|
142
147
|
delete existingRules[method];
|
143
148
|
});
|
@@ -148,14 +153,14 @@ $.extend($.fn, {
|
|
148
153
|
var data = $.validator.normalizeRules(
|
149
154
|
$.extend(
|
150
155
|
{},
|
151
|
-
$.validator.metadataRules(element),
|
152
156
|
$.validator.classRules(element),
|
153
157
|
$.validator.attributeRules(element),
|
158
|
+
$.validator.dataRules(element),
|
154
159
|
$.validator.staticRules(element)
|
155
160
|
), element);
|
156
161
|
|
157
162
|
// make sure required is at front
|
158
|
-
if (data.required) {
|
163
|
+
if ( data.required ) {
|
159
164
|
var param = data.required;
|
160
165
|
delete data.required;
|
161
166
|
data = $.extend({required: param}, data);
|
@@ -168,11 +173,11 @@ $.extend($.fn, {
|
|
168
173
|
// Custom selectors
|
169
174
|
$.extend($.expr[":"], {
|
170
175
|
// http://docs.jquery.com/Plugins/Validation/blank
|
171
|
-
blank: function(a) {return !$.trim("" + a.
|
176
|
+
blank: function( a ) { return !$.trim("" + $(a).val()); },
|
172
177
|
// http://docs.jquery.com/Plugins/Validation/filled
|
173
|
-
filled: function(a) {return !!$.trim("" + a.
|
178
|
+
filled: function( a ) { return !!$.trim("" + $(a).val()); },
|
174
179
|
// http://docs.jquery.com/Plugins/Validation/unchecked
|
175
|
-
unchecked: function(a) {return
|
180
|
+
unchecked: function( a ) { return !$(a).prop("checked"); }
|
176
181
|
});
|
177
182
|
|
178
183
|
// constructor for validator
|
@@ -182,21 +187,24 @@ $.validator = function( options, form ) {
|
|
182
187
|
this.init();
|
183
188
|
};
|
184
189
|
|
185
|
-
$.validator.format = function(source, params) {
|
186
|
-
if ( arguments.length
|
190
|
+
$.validator.format = function( source, params ) {
|
191
|
+
if ( arguments.length === 1 ) {
|
187
192
|
return function() {
|
188
193
|
var args = $.makeArray(arguments);
|
189
194
|
args.unshift(source);
|
190
195
|
return $.validator.format.apply( this, args );
|
191
196
|
};
|
192
|
-
|
197
|
+
}
|
198
|
+
if ( arguments.length > 2 && params.constructor !== Array ) {
|
193
199
|
params = $.makeArray(arguments).slice(1);
|
194
200
|
}
|
195
|
-
if ( params.constructor
|
201
|
+
if ( params.constructor !== Array ) {
|
196
202
|
params = [ params ];
|
197
203
|
}
|
198
|
-
$.each(params, function(i, n) {
|
199
|
-
source = source.replace(new RegExp("\\{" + i + "\\}", "g"),
|
204
|
+
$.each(params, function( i, n ) {
|
205
|
+
source = source.replace( new RegExp("\\{" + i + "\\}", "g"), function() {
|
206
|
+
return n;
|
207
|
+
});
|
200
208
|
});
|
201
209
|
return source;
|
202
210
|
};
|
@@ -211,47 +219,53 @@ $.extend($.validator, {
|
|
211
219
|
validClass: "valid",
|
212
220
|
errorElement: "label",
|
213
221
|
focusInvalid: true,
|
214
|
-
errorContainer: $(
|
215
|
-
errorLabelContainer: $(
|
222
|
+
errorContainer: $([]),
|
223
|
+
errorLabelContainer: $([]),
|
216
224
|
onsubmit: true,
|
217
225
|
ignore: ":hidden",
|
218
226
|
ignoreTitle: false,
|
219
|
-
onfocusin: function(element, event) {
|
227
|
+
onfocusin: function( element, event ) {
|
220
228
|
this.lastActive = element;
|
221
229
|
|
222
230
|
// hide error label and remove error class on focus if enabled
|
223
231
|
if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
|
224
|
-
|
232
|
+
if ( this.settings.unhighlight ) {
|
233
|
+
this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
|
234
|
+
}
|
225
235
|
this.addWrapper(this.errorsFor(element)).hide();
|
226
236
|
}
|
227
237
|
},
|
228
|
-
onfocusout: function(element, event) {
|
238
|
+
onfocusout: function( element, event ) {
|
229
239
|
if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
|
230
240
|
this.element(element);
|
231
241
|
}
|
232
242
|
},
|
233
|
-
onkeyup: function(element, event) {
|
234
|
-
if (
|
243
|
+
onkeyup: function( element, event ) {
|
244
|
+
if ( event.which === 9 && this.elementValue(element) === "" ) {
|
245
|
+
return;
|
246
|
+
} else if ( element.name in this.submitted || element === this.lastElement ) {
|
235
247
|
this.element(element);
|
236
248
|
}
|
237
249
|
},
|
238
|
-
onclick: function(element, event) {
|
250
|
+
onclick: function( element, event ) {
|
239
251
|
// click on selects, radiobuttons and checkboxes
|
240
|
-
if ( element.name in this.submitted )
|
252
|
+
if ( element.name in this.submitted ) {
|
241
253
|
this.element(element);
|
254
|
+
}
|
242
255
|
// or option elements, check parent select in that case
|
243
|
-
else if (element.parentNode.name in this.submitted)
|
256
|
+
else if ( element.parentNode.name in this.submitted ) {
|
244
257
|
this.element(element.parentNode);
|
258
|
+
}
|
245
259
|
},
|
246
|
-
highlight: function(element, errorClass, validClass) {
|
247
|
-
if (element.type ===
|
260
|
+
highlight: function( element, errorClass, validClass ) {
|
261
|
+
if ( element.type === "radio" ) {
|
248
262
|
this.findByName(element.name).addClass(errorClass).removeClass(validClass);
|
249
263
|
} else {
|
250
264
|
$(element).addClass(errorClass).removeClass(validClass);
|
251
265
|
}
|
252
266
|
},
|
253
|
-
unhighlight: function(element, errorClass, validClass) {
|
254
|
-
if (element.type ===
|
267
|
+
unhighlight: function( element, errorClass, validClass ) {
|
268
|
+
if ( element.type === "radio" ) {
|
255
269
|
this.findByName(element.name).removeClass(errorClass).addClass(validClass);
|
256
270
|
} else {
|
257
271
|
$(element).removeClass(errorClass).addClass(validClass);
|
@@ -260,7 +274,7 @@ $.extend($.validator, {
|
|
260
274
|
},
|
261
275
|
|
262
276
|
// http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
|
263
|
-
setDefaults: function(settings) {
|
277
|
+
setDefaults: function( settings ) {
|
264
278
|
$.extend( $.validator.defaults, settings );
|
265
279
|
},
|
266
280
|
|
@@ -275,7 +289,6 @@ $.extend($.validator, {
|
|
275
289
|
digits: "Please enter only digits.",
|
276
290
|
creditcard: "Please enter a valid credit card number.",
|
277
291
|
equalTo: "Please enter the same value again.",
|
278
|
-
accept: "Please enter a value with a valid extension.",
|
279
292
|
maxlength: $.validator.format("Please enter no more than {0} characters."),
|
280
293
|
minlength: $.validator.format("Please enter at least {0} characters."),
|
281
294
|
rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
|
@@ -300,32 +313,38 @@ $.extend($.validator, {
|
|
300
313
|
this.reset();
|
301
314
|
|
302
315
|
var groups = (this.groups = {});
|
303
|
-
$.each(this.settings.groups, function(key, value) {
|
304
|
-
|
316
|
+
$.each(this.settings.groups, function( key, value ) {
|
317
|
+
if ( typeof value === "string" ) {
|
318
|
+
value = value.split(/\s/);
|
319
|
+
}
|
320
|
+
$.each(value, function( index, name ) {
|
305
321
|
groups[name] = key;
|
306
322
|
});
|
307
323
|
});
|
308
324
|
var rules = this.settings.rules;
|
309
|
-
$.each(rules, function(key, value) {
|
325
|
+
$.each(rules, function( key, value ) {
|
310
326
|
rules[key] = $.validator.normalizeRule(value);
|
311
327
|
});
|
312
328
|
|
313
329
|
function delegate(event) {
|
314
330
|
var validator = $.data(this[0].form, "validator"),
|
315
331
|
eventType = "on" + event.type.replace(/^validate/, "");
|
316
|
-
|
332
|
+
if ( validator.settings[eventType] ) {
|
333
|
+
validator.settings[eventType].call(validator, this[0], event);
|
334
|
+
}
|
317
335
|
}
|
318
336
|
$(this.currentForm)
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
337
|
+
.validateDelegate(":text, [type='password'], [type='file'], select, textarea, " +
|
338
|
+
"[type='number'], [type='search'] ,[type='tel'], [type='url'], " +
|
339
|
+
"[type='email'], [type='datetime'], [type='date'], [type='month'], " +
|
340
|
+
"[type='week'], [type='time'], [type='datetime-local'], " +
|
341
|
+
"[type='range'], [type='color'] ",
|
342
|
+
"focusin focusout keyup", delegate)
|
325
343
|
.validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate);
|
326
344
|
|
327
|
-
if (this.settings.invalidHandler)
|
345
|
+
if ( this.settings.invalidHandler ) {
|
328
346
|
$(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
|
347
|
+
}
|
329
348
|
},
|
330
349
|
|
331
350
|
// http://docs.jquery.com/Plugins/Validation/Validator/form
|
@@ -333,8 +352,9 @@ $.extend($.validator, {
|
|
333
352
|
this.checkForm();
|
334
353
|
$.extend(this.submitted, this.errorMap);
|
335
354
|
this.invalid = $.extend({}, this.errorMap);
|
336
|
-
if (!this.valid())
|
355
|
+
if ( !this.valid() ) {
|
337
356
|
$(this.currentForm).triggerHandler("invalid-form", [this]);
|
357
|
+
}
|
338
358
|
this.showErrors();
|
339
359
|
return this.valid();
|
340
360
|
},
|
@@ -353,7 +373,7 @@ $.extend($.validator, {
|
|
353
373
|
this.lastElement = element;
|
354
374
|
this.prepareElement( element );
|
355
375
|
this.currentElements = $(element);
|
356
|
-
var result = this.check( element );
|
376
|
+
var result = this.check( element ) !== false;
|
357
377
|
if ( result ) {
|
358
378
|
delete this.invalid[element.name];
|
359
379
|
} else {
|
@@ -368,8 +388,8 @@ $.extend($.validator, {
|
|
368
388
|
},
|
369
389
|
|
370
390
|
// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
|
371
|
-
showErrors: function(errors) {
|
372
|
-
if(errors) {
|
391
|
+
showErrors: function( errors ) {
|
392
|
+
if ( errors ) {
|
373
393
|
// add items to error list and map
|
374
394
|
$.extend( this.errorMap, errors );
|
375
395
|
this.errorList = [];
|
@@ -380,24 +400,27 @@ $.extend($.validator, {
|
|
380
400
|
});
|
381
401
|
}
|
382
402
|
// remove items from success list
|
383
|
-
this.successList = $.grep( this.successList, function(element) {
|
403
|
+
this.successList = $.grep( this.successList, function( element ) {
|
384
404
|
return !(element.name in errors);
|
385
405
|
});
|
386
406
|
}
|
387
|
-
this.settings.showErrors
|
388
|
-
|
389
|
-
|
407
|
+
if ( this.settings.showErrors ) {
|
408
|
+
this.settings.showErrors.call( this, this.errorMap, this.errorList );
|
409
|
+
} else {
|
410
|
+
this.defaultShowErrors();
|
411
|
+
}
|
390
412
|
},
|
391
413
|
|
392
414
|
// http://docs.jquery.com/Plugins/Validation/Validator/resetForm
|
393
415
|
resetForm: function() {
|
394
|
-
if ( $.fn.resetForm )
|
395
|
-
$(
|
416
|
+
if ( $.fn.resetForm ) {
|
417
|
+
$(this.currentForm).resetForm();
|
418
|
+
}
|
396
419
|
this.submitted = {};
|
397
420
|
this.lastElement = null;
|
398
421
|
this.prepareForm();
|
399
422
|
this.hideErrors();
|
400
|
-
this.elements().removeClass( this.settings.errorClass );
|
423
|
+
this.elements().removeClass( this.settings.errorClass ).removeData( "previousValue" );
|
401
424
|
},
|
402
425
|
|
403
426
|
numberOfInvalids: function() {
|
@@ -406,8 +429,9 @@ $.extend($.validator, {
|
|
406
429
|
|
407
430
|
objectLength: function( obj ) {
|
408
431
|
var count = 0;
|
409
|
-
for ( var i in obj )
|
432
|
+
for ( var i in obj ) {
|
410
433
|
count++;
|
434
|
+
}
|
411
435
|
return count;
|
412
436
|
},
|
413
437
|
|
@@ -416,7 +440,7 @@ $.extend($.validator, {
|
|
416
440
|
},
|
417
441
|
|
418
442
|
valid: function() {
|
419
|
-
return this.size()
|
443
|
+
return this.size() === 0;
|
420
444
|
},
|
421
445
|
|
422
446
|
size: function() {
|
@@ -424,7 +448,7 @@ $.extend($.validator, {
|
|
424
448
|
},
|
425
449
|
|
426
450
|
focusInvalid: function() {
|
427
|
-
if( this.settings.focusInvalid ) {
|
451
|
+
if ( this.settings.focusInvalid ) {
|
428
452
|
try {
|
429
453
|
$(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
|
430
454
|
.filter(":visible")
|
@@ -439,9 +463,9 @@ $.extend($.validator, {
|
|
439
463
|
|
440
464
|
findLastActive: function() {
|
441
465
|
var lastActive = this.lastActive;
|
442
|
-
return lastActive && $.grep(this.errorList, function(n) {
|
443
|
-
return n.element.name
|
444
|
-
}).length
|
466
|
+
return lastActive && $.grep(this.errorList, function( n ) {
|
467
|
+
return n.element.name === lastActive.name;
|
468
|
+
}).length === 1 && lastActive;
|
445
469
|
},
|
446
470
|
|
447
471
|
elements: function() {
|
@@ -454,11 +478,14 @@ $.extend($.validator, {
|
|
454
478
|
.not(":submit, :reset, :image, [disabled]")
|
455
479
|
.not( this.settings.ignore )
|
456
480
|
.filter(function() {
|
457
|
-
!this.name && validator.settings.debug && window.console
|
481
|
+
if ( !this.name && validator.settings.debug && window.console ) {
|
482
|
+
console.error( "%o has no name assigned", this);
|
483
|
+
}
|
458
484
|
|
459
485
|
// select only the first element for each name, and only those with rules specified
|
460
|
-
if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
|
486
|
+
if ( this.name in rulesCache || !validator.objectLength($(this).rules()) ) {
|
461
487
|
return false;
|
488
|
+
}
|
462
489
|
|
463
490
|
rulesCache[this.name] = true;
|
464
491
|
return true;
|
@@ -466,11 +493,12 @@ $.extend($.validator, {
|
|
466
493
|
},
|
467
494
|
|
468
495
|
clean: function( selector ) {
|
469
|
-
return $(
|
496
|
+
return $(selector)[0];
|
470
497
|
},
|
471
498
|
|
472
499
|
errors: function() {
|
473
|
-
|
500
|
+
var errorClass = this.settings.errorClass.replace(" ", ".");
|
501
|
+
return $(this.settings.errorElement + "." + errorClass, this.errorContext);
|
474
502
|
},
|
475
503
|
|
476
504
|
reset: function() {
|
@@ -492,80 +520,93 @@ $.extend($.validator, {
|
|
492
520
|
this.toHide = this.errorsFor(element);
|
493
521
|
},
|
494
522
|
|
523
|
+
elementValue: function( element ) {
|
524
|
+
var type = $(element).attr("type"),
|
525
|
+
val = $(element).val();
|
526
|
+
|
527
|
+
if ( type === "radio" || type === "checkbox" ) {
|
528
|
+
return $("input[name='" + $(element).attr("name") + "']:checked").val();
|
529
|
+
}
|
530
|
+
|
531
|
+
if ( typeof val === "string" ) {
|
532
|
+
return val.replace(/\r/g, "");
|
533
|
+
}
|
534
|
+
return val;
|
535
|
+
},
|
536
|
+
|
495
537
|
check: function( element ) {
|
496
538
|
element = this.validationTargetFor( this.clean( element ) );
|
497
539
|
|
498
540
|
var rules = $(element).rules();
|
499
541
|
var dependencyMismatch = false;
|
542
|
+
var val = this.elementValue(element);
|
543
|
+
var result;
|
544
|
+
|
500
545
|
for (var method in rules ) {
|
501
546
|
var rule = { method: method, parameters: rules[method] };
|
502
547
|
try {
|
503
|
-
|
548
|
+
|
549
|
+
result = $.validator.methods[method].call( this, val, element, rule.parameters );
|
504
550
|
|
505
551
|
// if a method indicates that the field is optional and therefore valid,
|
506
552
|
// don't mark it as valid when there are no other rules
|
507
|
-
if ( result
|
553
|
+
if ( result === "dependency-mismatch" ) {
|
508
554
|
dependencyMismatch = true;
|
509
555
|
continue;
|
510
556
|
}
|
511
557
|
dependencyMismatch = false;
|
512
558
|
|
513
|
-
if ( result
|
559
|
+
if ( result === "pending" ) {
|
514
560
|
this.toHide = this.toHide.not( this.errorsFor(element) );
|
515
561
|
return;
|
516
562
|
}
|
517
563
|
|
518
|
-
if( !result ) {
|
564
|
+
if ( !result ) {
|
519
565
|
this.formatAndAdd( element, rule );
|
520
566
|
return false;
|
521
567
|
}
|
522
568
|
} catch(e) {
|
523
|
-
this.settings.debug && window.console
|
524
|
-
|
569
|
+
if ( this.settings.debug && window.console ) {
|
570
|
+
console.log( "Exception occurred when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
|
571
|
+
}
|
525
572
|
throw e;
|
526
573
|
}
|
527
574
|
}
|
528
|
-
if (dependencyMismatch)
|
575
|
+
if ( dependencyMismatch ) {
|
529
576
|
return;
|
530
|
-
|
577
|
+
}
|
578
|
+
if ( this.objectLength(rules) ) {
|
531
579
|
this.successList.push(element);
|
580
|
+
}
|
532
581
|
return true;
|
533
582
|
},
|
534
583
|
|
535
584
|
// return the custom message for the given element and validation method
|
536
|
-
// specified in the element's
|
537
|
-
|
538
|
-
|
539
|
-
return;
|
540
|
-
|
541
|
-
var meta = this.settings.meta
|
542
|
-
? $(element).metadata()[this.settings.meta]
|
543
|
-
: $(element).metadata();
|
544
|
-
|
545
|
-
return meta && meta.messages && meta.messages[method];
|
585
|
+
// specified in the element's HTML5 data attribute
|
586
|
+
customDataMessage: function( element, method ) {
|
587
|
+
return $(element).data("msg-" + method.toLowerCase()) || (element.attributes && $(element).attr("data-msg-" + method.toLowerCase()));
|
546
588
|
},
|
547
589
|
|
548
590
|
// return the custom message for the given element name and validation method
|
549
591
|
customMessage: function( name, method ) {
|
550
592
|
var m = this.settings.messages[name];
|
551
|
-
return m && (m.constructor
|
552
|
-
? m
|
553
|
-
: m[method]);
|
593
|
+
return m && (m.constructor === String ? m : m[method]);
|
554
594
|
},
|
555
595
|
|
556
596
|
// return the first defined argument, allowing empty strings
|
557
597
|
findDefined: function() {
|
558
598
|
for(var i = 0; i < arguments.length; i++) {
|
559
|
-
if (arguments[i] !== undefined)
|
599
|
+
if ( arguments[i] !== undefined ) {
|
560
600
|
return arguments[i];
|
601
|
+
}
|
561
602
|
}
|
562
603
|
return undefined;
|
563
604
|
},
|
564
605
|
|
565
|
-
defaultMessage: function( element, method) {
|
606
|
+
defaultMessage: function( element, method ) {
|
566
607
|
return this.findDefined(
|
567
608
|
this.customMessage( element.name, method ),
|
568
|
-
this.
|
609
|
+
this.customDataMessage( element, method ),
|
569
610
|
// title is never undefined, so handle empty string as undefined
|
570
611
|
!this.settings.ignoreTitle && element.title || undefined,
|
571
612
|
$.validator.messages[method],
|
@@ -576,10 +617,10 @@ $.extend($.validator, {
|
|
576
617
|
formatAndAdd: function( element, rule ) {
|
577
618
|
var message = this.defaultMessage( element, rule.method ),
|
578
619
|
theregex = /\$?\{(\d+)\}/g;
|
579
|
-
if ( typeof message
|
620
|
+
if ( typeof message === "function" ) {
|
580
621
|
message = message.call(this, rule.parameters, element);
|
581
622
|
} else if (theregex.test(message)) {
|
582
|
-
message =
|
623
|
+
message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
|
583
624
|
}
|
584
625
|
this.errorList.push({
|
585
626
|
message: message,
|
@@ -590,28 +631,32 @@ $.extend($.validator, {
|
|
590
631
|
this.submitted[element.name] = message;
|
591
632
|
},
|
592
633
|
|
593
|
-
addWrapper: function(toToggle) {
|
594
|
-
if ( this.settings.wrapper )
|
634
|
+
addWrapper: function( toToggle ) {
|
635
|
+
if ( this.settings.wrapper ) {
|
595
636
|
toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
|
637
|
+
}
|
596
638
|
return toToggle;
|
597
639
|
},
|
598
640
|
|
599
641
|
defaultShowErrors: function() {
|
600
|
-
|
642
|
+
var i, elements;
|
643
|
+
for ( i = 0; this.errorList[i]; i++ ) {
|
601
644
|
var error = this.errorList[i];
|
602
|
-
|
645
|
+
if ( this.settings.highlight ) {
|
646
|
+
this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
|
647
|
+
}
|
603
648
|
this.showLabel( error.element, error.message );
|
604
649
|
}
|
605
|
-
if( this.errorList.length ) {
|
650
|
+
if ( this.errorList.length ) {
|
606
651
|
this.toShow = this.toShow.add( this.containers );
|
607
652
|
}
|
608
|
-
if (this.settings.success) {
|
609
|
-
for (
|
653
|
+
if ( this.settings.success ) {
|
654
|
+
for ( i = 0; this.successList[i]; i++ ) {
|
610
655
|
this.showLabel( this.successList[i] );
|
611
656
|
}
|
612
657
|
}
|
613
|
-
if (this.settings.unhighlight) {
|
614
|
-
for (
|
658
|
+
if ( this.settings.unhighlight ) {
|
659
|
+
for ( i = 0, elements = this.validElements(); elements[i]; i++ ) {
|
615
660
|
this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
|
616
661
|
}
|
617
662
|
}
|
@@ -630,18 +675,17 @@ $.extend($.validator, {
|
|
630
675
|
});
|
631
676
|
},
|
632
677
|
|
633
|
-
showLabel: function(element, message) {
|
678
|
+
showLabel: function( element, message ) {
|
634
679
|
var label = this.errorsFor( element );
|
635
680
|
if ( label.length ) {
|
636
681
|
// refresh error/success class
|
637
682
|
label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
|
638
|
-
|
639
|
-
|
640
|
-
label.attr("generated") && label.html(message);
|
683
|
+
// replace message on existing label
|
684
|
+
label.html(message);
|
641
685
|
} else {
|
642
686
|
// create label
|
643
|
-
label = $("<" + this.settings.errorElement + "
|
644
|
-
.attr(
|
687
|
+
label = $("<" + this.settings.errorElement + ">")
|
688
|
+
.attr("for", this.idOrName(element))
|
645
689
|
.addClass(this.settings.errorClass)
|
646
690
|
.html(message || "");
|
647
691
|
if ( this.settings.wrapper ) {
|
@@ -649,107 +693,109 @@ $.extend($.validator, {
|
|
649
693
|
// actually showing the wrapped element is handled elsewhere
|
650
694
|
label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
|
651
695
|
}
|
652
|
-
if ( !this.labelContainer.append(label).length )
|
653
|
-
this.settings.errorPlacement
|
654
|
-
|
655
|
-
|
696
|
+
if ( !this.labelContainer.append(label).length ) {
|
697
|
+
if ( this.settings.errorPlacement ) {
|
698
|
+
this.settings.errorPlacement(label, $(element) );
|
699
|
+
} else {
|
700
|
+
label.insertAfter(element);
|
701
|
+
}
|
702
|
+
}
|
656
703
|
}
|
657
704
|
if ( !message && this.settings.success ) {
|
658
705
|
label.text("");
|
659
|
-
typeof this.settings.success
|
660
|
-
|
661
|
-
|
706
|
+
if ( typeof this.settings.success === "string" ) {
|
707
|
+
label.addClass( this.settings.success );
|
708
|
+
} else {
|
709
|
+
this.settings.success( label, element );
|
710
|
+
}
|
662
711
|
}
|
663
712
|
this.toShow = this.toShow.add(label);
|
664
713
|
},
|
665
714
|
|
666
|
-
errorsFor: function(element) {
|
715
|
+
errorsFor: function( element ) {
|
667
716
|
var name = this.idOrName(element);
|
668
|
-
|
669
|
-
return $(this).attr(
|
717
|
+
return this.errors().filter(function() {
|
718
|
+
return $(this).attr("for") === name;
|
670
719
|
});
|
671
720
|
},
|
672
721
|
|
673
|
-
idOrName: function(element) {
|
722
|
+
idOrName: function( element ) {
|
674
723
|
return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
|
675
724
|
},
|
676
725
|
|
677
|
-
validationTargetFor: function(element) {
|
726
|
+
validationTargetFor: function( element ) {
|
678
727
|
// if radio/checkbox, validate first element in group instead
|
679
|
-
if (this.checkable(element)) {
|
728
|
+
if ( this.checkable(element) ) {
|
680
729
|
element = this.findByName( element.name ).not(this.settings.ignore)[0];
|
681
730
|
}
|
682
731
|
return element;
|
683
732
|
},
|
684
733
|
|
685
734
|
checkable: function( element ) {
|
686
|
-
return /radio|checkbox/i.test(element.type);
|
735
|
+
return (/radio|checkbox/i).test(element.type);
|
687
736
|
},
|
688
737
|
|
689
738
|
findByName: function( name ) {
|
690
|
-
|
691
|
-
var form = this.currentForm;
|
692
|
-
return $(document.getElementsByName(name)).map(function(index, element) {
|
693
|
-
return element.form == form && element.name == name && element || null;
|
694
|
-
});
|
739
|
+
return $(this.currentForm).find("[name='" + name + "']");
|
695
740
|
},
|
696
741
|
|
697
|
-
getLength: function(value, element) {
|
742
|
+
getLength: function( value, element ) {
|
698
743
|
switch( element.nodeName.toLowerCase() ) {
|
699
|
-
case
|
744
|
+
case "select":
|
700
745
|
return $("option:selected", element).length;
|
701
|
-
case
|
702
|
-
if( this.checkable( element) )
|
703
|
-
return this.findByName(element.name).filter(
|
746
|
+
case "input":
|
747
|
+
if ( this.checkable( element) ) {
|
748
|
+
return this.findByName(element.name).filter(":checked").length;
|
749
|
+
}
|
704
750
|
}
|
705
751
|
return value.length;
|
706
752
|
},
|
707
753
|
|
708
|
-
depend: function(param, element) {
|
709
|
-
return this.dependTypes[typeof param]
|
710
|
-
? this.dependTypes[typeof param](param, element)
|
711
|
-
: true;
|
754
|
+
depend: function( param, element ) {
|
755
|
+
return this.dependTypes[typeof param] ? this.dependTypes[typeof param](param, element) : true;
|
712
756
|
},
|
713
757
|
|
714
758
|
dependTypes: {
|
715
|
-
"boolean": function(param, element) {
|
759
|
+
"boolean": function( param, element ) {
|
716
760
|
return param;
|
717
761
|
},
|
718
|
-
"string": function(param, element) {
|
762
|
+
"string": function( param, element ) {
|
719
763
|
return !!$(param, element.form).length;
|
720
764
|
},
|
721
|
-
"function": function(param, element) {
|
765
|
+
"function": function( param, element ) {
|
722
766
|
return param(element);
|
723
767
|
}
|
724
768
|
},
|
725
769
|
|
726
|
-
optional: function(element) {
|
727
|
-
|
770
|
+
optional: function( element ) {
|
771
|
+
var val = this.elementValue(element);
|
772
|
+
return !$.validator.methods.required.call(this, val, element) && "dependency-mismatch";
|
728
773
|
},
|
729
774
|
|
730
|
-
startRequest: function(element) {
|
731
|
-
if (!this.pending[element.name]) {
|
775
|
+
startRequest: function( element ) {
|
776
|
+
if ( !this.pending[element.name] ) {
|
732
777
|
this.pendingRequest++;
|
733
778
|
this.pending[element.name] = true;
|
734
779
|
}
|
735
780
|
},
|
736
781
|
|
737
|
-
stopRequest: function(element, valid) {
|
782
|
+
stopRequest: function( element, valid ) {
|
738
783
|
this.pendingRequest--;
|
739
784
|
// sometimes synchronization fails, make sure pendingRequest is never < 0
|
740
|
-
if (this.pendingRequest < 0)
|
785
|
+
if ( this.pendingRequest < 0 ) {
|
741
786
|
this.pendingRequest = 0;
|
787
|
+
}
|
742
788
|
delete this.pending[element.name];
|
743
|
-
if ( valid && this.pendingRequest
|
789
|
+
if ( valid && this.pendingRequest === 0 && this.formSubmitted && this.form() ) {
|
744
790
|
$(this.currentForm).submit();
|
745
791
|
this.formSubmitted = false;
|
746
|
-
} else if (!valid && this.pendingRequest
|
792
|
+
} else if (!valid && this.pendingRequest === 0 && this.formSubmitted) {
|
747
793
|
$(this.currentForm).triggerHandler("invalid-form", [this]);
|
748
794
|
this.formSubmitted = false;
|
749
795
|
}
|
750
796
|
},
|
751
797
|
|
752
|
-
previousValue: function(element) {
|
798
|
+
previousValue: function( element ) {
|
753
799
|
return $.data(element, "previousValue") || $.data(element, "previousValue", {
|
754
800
|
old: null,
|
755
801
|
valid: true,
|
@@ -765,94 +811,117 @@ $.extend($.validator, {
|
|
765
811
|
url: {url: true},
|
766
812
|
date: {date: true},
|
767
813
|
dateISO: {dateISO: true},
|
768
|
-
dateDE: {dateDE: true},
|
769
814
|
number: {number: true},
|
770
|
-
numberDE: {numberDE: true},
|
771
815
|
digits: {digits: true},
|
772
816
|
creditcard: {creditcard: true}
|
773
817
|
},
|
774
818
|
|
775
|
-
addClassRules: function(className, rules) {
|
776
|
-
className.constructor
|
777
|
-
this.classRuleSettings[className] = rules
|
819
|
+
addClassRules: function( className, rules ) {
|
820
|
+
if ( className.constructor === String ) {
|
821
|
+
this.classRuleSettings[className] = rules;
|
822
|
+
} else {
|
778
823
|
$.extend(this.classRuleSettings, className);
|
824
|
+
}
|
779
825
|
},
|
780
826
|
|
781
|
-
classRules: function(element) {
|
827
|
+
classRules: function( element ) {
|
782
828
|
var rules = {};
|
783
|
-
var classes = $(element).attr(
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
829
|
+
var classes = $(element).attr("class");
|
830
|
+
if ( classes ) {
|
831
|
+
$.each(classes.split(" "), function() {
|
832
|
+
if ( this in $.validator.classRuleSettings ) {
|
833
|
+
$.extend(rules, $.validator.classRuleSettings[this]);
|
834
|
+
}
|
835
|
+
});
|
836
|
+
}
|
789
837
|
return rules;
|
790
838
|
},
|
791
839
|
|
792
|
-
attributeRules: function(element) {
|
840
|
+
attributeRules: function( element ) {
|
793
841
|
var rules = {};
|
794
842
|
var $element = $(element);
|
843
|
+
var type = $element[0].getAttribute("type");
|
795
844
|
|
796
845
|
for (var method in $.validator.methods) {
|
797
846
|
var value;
|
798
|
-
|
799
|
-
|
800
|
-
|
847
|
+
|
848
|
+
// support for <input required> in both html5 and older browsers
|
849
|
+
if ( method === "required" ) {
|
850
|
+
value = $element.get(0).getAttribute(method);
|
851
|
+
// Some browsers return an empty string for the required attribute
|
852
|
+
// and non-HTML5 browsers might have required="" markup
|
853
|
+
if ( value === "" ) {
|
854
|
+
value = true;
|
855
|
+
}
|
856
|
+
// force non-HTML5 browsers to return bool
|
857
|
+
value = !!value;
|
801
858
|
} else {
|
802
859
|
value = $element.attr(method);
|
803
860
|
}
|
804
|
-
|
861
|
+
|
862
|
+
// convert the value to a number for number inputs, and for text for backwards compability
|
863
|
+
// allows type="date" and others to be compared as strings
|
864
|
+
if ( /min|max/.test( method ) && ( type === null || /number|range|text/.test( type ) ) ) {
|
865
|
+
value = Number(value);
|
866
|
+
}
|
867
|
+
|
868
|
+
if ( value ) {
|
805
869
|
rules[method] = value;
|
806
|
-
} else if (
|
870
|
+
} else if ( type === method && type !== 'range' ) {
|
871
|
+
// exception: the jquery validate 'range' method
|
872
|
+
// does not test for the html5 'range' type
|
807
873
|
rules[method] = true;
|
808
874
|
}
|
809
875
|
}
|
810
876
|
|
811
877
|
// maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
|
812
|
-
if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
|
878
|
+
if ( rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength) ) {
|
813
879
|
delete rules.maxlength;
|
814
880
|
}
|
815
881
|
|
816
882
|
return rules;
|
817
883
|
},
|
818
884
|
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
885
|
+
dataRules: function( element ) {
|
886
|
+
var method, value,
|
887
|
+
rules = {}, $element = $(element);
|
888
|
+
for (method in $.validator.methods) {
|
889
|
+
value = $element.data("rule-" + method.toLowerCase());
|
890
|
+
if ( value !== undefined ) {
|
891
|
+
rules[method] = value;
|
892
|
+
}
|
893
|
+
}
|
894
|
+
return rules;
|
826
895
|
},
|
827
896
|
|
828
|
-
staticRules: function(element) {
|
897
|
+
staticRules: function( element ) {
|
829
898
|
var rules = {};
|
830
|
-
var validator = $.data(element.form,
|
831
|
-
if (validator.settings.rules) {
|
899
|
+
var validator = $.data(element.form, "validator");
|
900
|
+
if ( validator.settings.rules ) {
|
832
901
|
rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
|
833
902
|
}
|
834
903
|
return rules;
|
835
904
|
},
|
836
905
|
|
837
|
-
normalizeRules: function(rules, element) {
|
906
|
+
normalizeRules: function( rules, element ) {
|
838
907
|
// handle dependency check
|
839
|
-
$.each(rules, function(prop, val) {
|
908
|
+
$.each(rules, function( prop, val ) {
|
840
909
|
// ignore rule when param is explicitly false, eg. required:false
|
841
|
-
if (val === false) {
|
910
|
+
if ( val === false ) {
|
842
911
|
delete rules[prop];
|
843
912
|
return;
|
844
913
|
}
|
845
|
-
if (val.param || val.depends) {
|
914
|
+
if ( val.param || val.depends ) {
|
846
915
|
var keepRule = true;
|
847
916
|
switch (typeof val.depends) {
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
917
|
+
case "string":
|
918
|
+
keepRule = !!$(val.depends, element.form).length;
|
919
|
+
break;
|
920
|
+
case "function":
|
921
|
+
keepRule = val.depends.call(element, element);
|
922
|
+
break;
|
854
923
|
}
|
855
|
-
if (keepRule) {
|
924
|
+
if ( keepRule ) {
|
856
925
|
rules[prop] = val.param !== undefined ? val.param : true;
|
857
926
|
} else {
|
858
927
|
delete rules[prop];
|
@@ -861,47 +930,48 @@ $.extend($.validator, {
|
|
861
930
|
});
|
862
931
|
|
863
932
|
// evaluate parameters
|
864
|
-
$.each(rules, function(rule, parameter) {
|
933
|
+
$.each(rules, function( rule, parameter ) {
|
865
934
|
rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
|
866
935
|
});
|
867
936
|
|
868
937
|
// clean number parameters
|
869
|
-
$.each(['minlength', 'maxlength'
|
870
|
-
if (rules[this]) {
|
938
|
+
$.each(['minlength', 'maxlength'], function() {
|
939
|
+
if ( rules[this] ) {
|
871
940
|
rules[this] = Number(rules[this]);
|
872
941
|
}
|
873
942
|
});
|
874
943
|
$.each(['rangelength', 'range'], function() {
|
875
|
-
|
876
|
-
|
944
|
+
var parts;
|
945
|
+
if ( rules[this] ) {
|
946
|
+
if ( $.isArray(rules[this]) ) {
|
947
|
+
rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
|
948
|
+
} else if ( typeof rules[this] === "string" ) {
|
949
|
+
parts = rules[this].split(/[\s,]+/);
|
950
|
+
rules[this] = [Number(parts[0]), Number(parts[1])];
|
951
|
+
}
|
877
952
|
}
|
878
953
|
});
|
879
954
|
|
880
|
-
if ($.validator.autoCreateRanges) {
|
955
|
+
if ( $.validator.autoCreateRanges ) {
|
881
956
|
// auto-create ranges
|
882
|
-
if (rules.min && rules.max) {
|
957
|
+
if ( rules.min && rules.max ) {
|
883
958
|
rules.range = [rules.min, rules.max];
|
884
959
|
delete rules.min;
|
885
960
|
delete rules.max;
|
886
961
|
}
|
887
|
-
if (rules.minlength && rules.maxlength) {
|
962
|
+
if ( rules.minlength && rules.maxlength ) {
|
888
963
|
rules.rangelength = [rules.minlength, rules.maxlength];
|
889
964
|
delete rules.minlength;
|
890
965
|
delete rules.maxlength;
|
891
966
|
}
|
892
967
|
}
|
893
968
|
|
894
|
-
// To support custom messages in metadata ignore rule methods titled "messages"
|
895
|
-
if (rules.messages) {
|
896
|
-
delete rules.messages;
|
897
|
-
}
|
898
|
-
|
899
969
|
return rules;
|
900
970
|
},
|
901
971
|
|
902
972
|
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
|
903
|
-
normalizeRule: function(data) {
|
904
|
-
if( typeof data
|
973
|
+
normalizeRule: function( data ) {
|
974
|
+
if ( typeof data === "string" ) {
|
905
975
|
var transformed = {};
|
906
976
|
$.each(data.split(/\s/), function() {
|
907
977
|
transformed[this] = true;
|
@@ -912,10 +982,10 @@ $.extend($.validator, {
|
|
912
982
|
},
|
913
983
|
|
914
984
|
// http://docs.jquery.com/Plugins/Validation/Validator/addMethod
|
915
|
-
addMethod: function(name, method, message) {
|
985
|
+
addMethod: function( name, method, message ) {
|
916
986
|
$.validator.methods[name] = method;
|
917
|
-
$.validator.messages[name] = message
|
918
|
-
if (method.length < 3) {
|
987
|
+
$.validator.messages[name] = message !== undefined ? message : $.validator.messages[name];
|
988
|
+
if ( method.length < 3 ) {
|
919
989
|
$.validator.addClassRules(name, $.validator.normalizeRule(name));
|
920
990
|
}
|
921
991
|
},
|
@@ -923,147 +993,64 @@ $.extend($.validator, {
|
|
923
993
|
methods: {
|
924
994
|
|
925
995
|
// http://docs.jquery.com/Plugins/Validation/Methods/required
|
926
|
-
required: function(value, element, param) {
|
996
|
+
required: function( value, element, param ) {
|
927
997
|
// check if dependency is met
|
928
|
-
if ( !this.depend(param, element) )
|
998
|
+
if ( !this.depend(param, element) ) {
|
929
999
|
return "dependency-mismatch";
|
930
|
-
|
931
|
-
|
1000
|
+
}
|
1001
|
+
if ( element.nodeName.toLowerCase() === "select" ) {
|
932
1002
|
// could be an array for select-multiple or a string, both are fine this way
|
933
1003
|
var val = $(element).val();
|
934
1004
|
return val && val.length > 0;
|
935
|
-
case 'input':
|
936
|
-
if ( this.checkable(element) )
|
937
|
-
return this.getLength(value, element) > 0;
|
938
|
-
default:
|
939
|
-
return $.trim(value).length > 0;
|
940
1005
|
}
|
941
|
-
|
942
|
-
|
943
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/remote
|
944
|
-
remote: function(value, element, param) {
|
945
|
-
if ( this.optional(element) )
|
946
|
-
return "dependency-mismatch";
|
947
|
-
|
948
|
-
var previous = this.previousValue(element);
|
949
|
-
if (!this.settings.messages[element.name] )
|
950
|
-
this.settings.messages[element.name] = {};
|
951
|
-
previous.originalMessage = this.settings.messages[element.name].remote;
|
952
|
-
this.settings.messages[element.name].remote = previous.message;
|
953
|
-
|
954
|
-
param = typeof param == "string" && {url:param} || param;
|
955
|
-
|
956
|
-
if ( this.pending[element.name] ) {
|
957
|
-
return "pending";
|
1006
|
+
if ( this.checkable(element) ) {
|
1007
|
+
return this.getLength(value, element) > 0;
|
958
1008
|
}
|
959
|
-
|
960
|
-
return previous.valid;
|
961
|
-
}
|
962
|
-
|
963
|
-
previous.old = value;
|
964
|
-
var validator = this;
|
965
|
-
this.startRequest(element);
|
966
|
-
var data = {};
|
967
|
-
data[element.name] = value;
|
968
|
-
$.ajax($.extend(true, {
|
969
|
-
url: param,
|
970
|
-
mode: "abort",
|
971
|
-
port: "validate" + element.name,
|
972
|
-
dataType: "json",
|
973
|
-
data: data,
|
974
|
-
success: function(response) {
|
975
|
-
validator.settings.messages[element.name].remote = previous.originalMessage;
|
976
|
-
var valid = response === true;
|
977
|
-
if ( valid ) {
|
978
|
-
var submitted = validator.formSubmitted;
|
979
|
-
validator.prepareElement(element);
|
980
|
-
validator.formSubmitted = submitted;
|
981
|
-
validator.successList.push(element);
|
982
|
-
validator.showErrors();
|
983
|
-
} else {
|
984
|
-
var errors = {};
|
985
|
-
var message = response || validator.defaultMessage( element, "remote" );
|
986
|
-
errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
|
987
|
-
validator.showErrors(errors);
|
988
|
-
}
|
989
|
-
previous.valid = valid;
|
990
|
-
validator.stopRequest(element, valid);
|
991
|
-
}
|
992
|
-
}, param));
|
993
|
-
return "pending";
|
994
|
-
},
|
995
|
-
|
996
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/minlength
|
997
|
-
minlength: function(value, element, param) {
|
998
|
-
return this.optional(element) || this.getLength($.trim(value), element) >= param;
|
999
|
-
},
|
1000
|
-
|
1001
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/maxlength
|
1002
|
-
maxlength: function(value, element, param) {
|
1003
|
-
return this.optional(element) || this.getLength($.trim(value), element) <= param;
|
1004
|
-
},
|
1005
|
-
|
1006
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/rangelength
|
1007
|
-
rangelength: function(value, element, param) {
|
1008
|
-
var length = this.getLength($.trim(value), element);
|
1009
|
-
return this.optional(element) || ( length >= param[0] && length <= param[1] );
|
1010
|
-
},
|
1011
|
-
|
1012
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/min
|
1013
|
-
min: function( value, element, param ) {
|
1014
|
-
return this.optional(element) || value >= param;
|
1015
|
-
},
|
1016
|
-
|
1017
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/max
|
1018
|
-
max: function( value, element, param ) {
|
1019
|
-
return this.optional(element) || value <= param;
|
1020
|
-
},
|
1021
|
-
|
1022
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/range
|
1023
|
-
range: function( value, element, param ) {
|
1024
|
-
return this.optional(element) || ( value >= param[0] && value <= param[1] );
|
1009
|
+
return $.trim(value).length > 0;
|
1025
1010
|
},
|
1026
1011
|
|
1027
1012
|
// http://docs.jquery.com/Plugins/Validation/Methods/email
|
1028
|
-
email: function(value, element) {
|
1013
|
+
email: function( value, element ) {
|
1029
1014
|
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
|
1030
1015
|
return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value);
|
1031
1016
|
},
|
1032
1017
|
|
1033
1018
|
// http://docs.jquery.com/Plugins/Validation/Methods/url
|
1034
|
-
url: function(value, element) {
|
1019
|
+
url: function( value, element ) {
|
1035
1020
|
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
|
1036
|
-
return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(
|
1021
|
+
return this.optional(element) || /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
|
1037
1022
|
},
|
1038
1023
|
|
1039
1024
|
// http://docs.jquery.com/Plugins/Validation/Methods/date
|
1040
|
-
date: function(value, element) {
|
1041
|
-
return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
|
1025
|
+
date: function( value, element ) {
|
1026
|
+
return this.optional(element) || !/Invalid|NaN/.test(new Date(value).toString());
|
1042
1027
|
},
|
1043
1028
|
|
1044
1029
|
// http://docs.jquery.com/Plugins/Validation/Methods/dateISO
|
1045
|
-
dateISO: function(value, element) {
|
1046
|
-
return this.optional(element) || /^\d{4}[
|
1030
|
+
dateISO: function( value, element ) {
|
1031
|
+
return this.optional(element) || /^\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}$/.test(value);
|
1047
1032
|
},
|
1048
1033
|
|
1049
1034
|
// http://docs.jquery.com/Plugins/Validation/Methods/number
|
1050
|
-
number: function(value, element) {
|
1051
|
-
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
|
1035
|
+
number: function( value, element ) {
|
1036
|
+
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$/.test(value);
|
1052
1037
|
},
|
1053
1038
|
|
1054
1039
|
// http://docs.jquery.com/Plugins/Validation/Methods/digits
|
1055
|
-
digits: function(value, element) {
|
1040
|
+
digits: function( value, element ) {
|
1056
1041
|
return this.optional(element) || /^\d+$/.test(value);
|
1057
1042
|
},
|
1058
1043
|
|
1059
1044
|
// http://docs.jquery.com/Plugins/Validation/Methods/creditcard
|
1060
1045
|
// based on http://en.wikipedia.org/wiki/Luhn
|
1061
|
-
creditcard: function(value, element) {
|
1062
|
-
if ( this.optional(element) )
|
1046
|
+
creditcard: function( value, element ) {
|
1047
|
+
if ( this.optional(element) ) {
|
1063
1048
|
return "dependency-mismatch";
|
1049
|
+
}
|
1064
1050
|
// accept only spaces, digits and dashes
|
1065
|
-
if (/[^0-9
|
1051
|
+
if ( /[^0-9 \-]+/.test(value) ) {
|
1066
1052
|
return false;
|
1053
|
+
}
|
1067
1054
|
var nCheck = 0,
|
1068
1055
|
nDigit = 0,
|
1069
1056
|
bEven = false;
|
@@ -1072,32 +1059,117 @@ $.extend($.validator, {
|
|
1072
1059
|
|
1073
1060
|
for (var n = value.length - 1; n >= 0; n--) {
|
1074
1061
|
var cDigit = value.charAt(n);
|
1075
|
-
|
1076
|
-
if (bEven) {
|
1077
|
-
if ((nDigit *= 2) > 9)
|
1062
|
+
nDigit = parseInt(cDigit, 10);
|
1063
|
+
if ( bEven ) {
|
1064
|
+
if ( (nDigit *= 2) > 9 ) {
|
1078
1065
|
nDigit -= 9;
|
1066
|
+
}
|
1079
1067
|
}
|
1080
1068
|
nCheck += nDigit;
|
1081
1069
|
bEven = !bEven;
|
1082
1070
|
}
|
1083
1071
|
|
1084
|
-
return (nCheck % 10)
|
1072
|
+
return (nCheck % 10) === 0;
|
1073
|
+
},
|
1074
|
+
|
1075
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/minlength
|
1076
|
+
minlength: function( value, element, param ) {
|
1077
|
+
var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
|
1078
|
+
return this.optional(element) || length >= param;
|
1079
|
+
},
|
1080
|
+
|
1081
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/maxlength
|
1082
|
+
maxlength: function( value, element, param ) {
|
1083
|
+
var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
|
1084
|
+
return this.optional(element) || length <= param;
|
1085
|
+
},
|
1086
|
+
|
1087
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/rangelength
|
1088
|
+
rangelength: function( value, element, param ) {
|
1089
|
+
var length = $.isArray( value ) ? value.length : this.getLength($.trim(value), element);
|
1090
|
+
return this.optional(element) || ( length >= param[0] && length <= param[1] );
|
1091
|
+
},
|
1092
|
+
|
1093
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/min
|
1094
|
+
min: function( value, element, param ) {
|
1095
|
+
return this.optional(element) || value >= param;
|
1085
1096
|
},
|
1086
1097
|
|
1087
|
-
// http://docs.jquery.com/Plugins/Validation/Methods/
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1098
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/max
|
1099
|
+
max: function( value, element, param ) {
|
1100
|
+
return this.optional(element) || value <= param;
|
1101
|
+
},
|
1102
|
+
|
1103
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/range
|
1104
|
+
range: function( value, element, param ) {
|
1105
|
+
return this.optional(element) || ( value >= param[0] && value <= param[1] );
|
1091
1106
|
},
|
1092
1107
|
|
1093
1108
|
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
|
1094
|
-
equalTo: function(value, element, param) {
|
1109
|
+
equalTo: function( value, element, param ) {
|
1095
1110
|
// bind to the blur event of the target in order to revalidate whenever the target field is updated
|
1096
1111
|
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
|
1097
|
-
var target = $(param)
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1112
|
+
var target = $(param);
|
1113
|
+
if ( this.settings.onfocusout ) {
|
1114
|
+
target.unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
|
1115
|
+
$(element).valid();
|
1116
|
+
});
|
1117
|
+
}
|
1118
|
+
return value === target.val();
|
1119
|
+
},
|
1120
|
+
|
1121
|
+
// http://docs.jquery.com/Plugins/Validation/Methods/remote
|
1122
|
+
remote: function( value, element, param ) {
|
1123
|
+
if ( this.optional(element) ) {
|
1124
|
+
return "dependency-mismatch";
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
var previous = this.previousValue(element);
|
1128
|
+
if (!this.settings.messages[element.name] ) {
|
1129
|
+
this.settings.messages[element.name] = {};
|
1130
|
+
}
|
1131
|
+
previous.originalMessage = this.settings.messages[element.name].remote;
|
1132
|
+
this.settings.messages[element.name].remote = previous.message;
|
1133
|
+
|
1134
|
+
param = typeof param === "string" && {url:param} || param;
|
1135
|
+
|
1136
|
+
if ( previous.old === value ) {
|
1137
|
+
return previous.valid;
|
1138
|
+
}
|
1139
|
+
|
1140
|
+
previous.old = value;
|
1141
|
+
var validator = this;
|
1142
|
+
this.startRequest(element);
|
1143
|
+
var data = {};
|
1144
|
+
data[element.name] = value;
|
1145
|
+
$.ajax($.extend(true, {
|
1146
|
+
url: param,
|
1147
|
+
mode: "abort",
|
1148
|
+
port: "validate" + element.name,
|
1149
|
+
dataType: "json",
|
1150
|
+
data: data,
|
1151
|
+
success: function( response ) {
|
1152
|
+
validator.settings.messages[element.name].remote = previous.originalMessage;
|
1153
|
+
var valid = response === true || response === "true";
|
1154
|
+
if ( valid ) {
|
1155
|
+
var submitted = validator.formSubmitted;
|
1156
|
+
validator.prepareElement(element);
|
1157
|
+
validator.formSubmitted = submitted;
|
1158
|
+
validator.successList.push(element);
|
1159
|
+
delete validator.invalid[element.name];
|
1160
|
+
validator.showErrors();
|
1161
|
+
} else {
|
1162
|
+
var errors = {};
|
1163
|
+
var message = response || validator.defaultMessage( element, "remote" );
|
1164
|
+
errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
|
1165
|
+
validator.invalid[element.name] = true;
|
1166
|
+
validator.showErrors(errors);
|
1167
|
+
}
|
1168
|
+
previous.valid = valid;
|
1169
|
+
validator.stopRequest(element, valid);
|
1170
|
+
}
|
1171
|
+
}, param));
|
1172
|
+
return "pending";
|
1101
1173
|
}
|
1102
1174
|
|
1103
1175
|
}
|
@@ -1107,18 +1179,18 @@ $.extend($.validator, {
|
|
1107
1179
|
// deprecated, use $.validator.format instead
|
1108
1180
|
$.format = $.validator.format;
|
1109
1181
|
|
1110
|
-
}
|
1182
|
+
}(jQuery));
|
1111
1183
|
|
1112
1184
|
// ajax mode: abort
|
1113
1185
|
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
|
1114
1186
|
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
|
1115
|
-
|
1187
|
+
(function($) {
|
1116
1188
|
var pendingRequests = {};
|
1117
1189
|
// Use a prefilter if available (1.5+)
|
1118
1190
|
if ( $.ajaxPrefilter ) {
|
1119
|
-
$.ajaxPrefilter(function(settings, _, xhr) {
|
1191
|
+
$.ajaxPrefilter(function( settings, _, xhr ) {
|
1120
1192
|
var port = settings.port;
|
1121
|
-
if (settings.mode
|
1193
|
+
if ( settings.mode === "abort" ) {
|
1122
1194
|
if ( pendingRequests[port] ) {
|
1123
1195
|
pendingRequests[port].abort();
|
1124
1196
|
}
|
@@ -1128,61 +1200,32 @@ $.format = $.validator.format;
|
|
1128
1200
|
} else {
|
1129
1201
|
// Proxy ajax
|
1130
1202
|
var ajax = $.ajax;
|
1131
|
-
$.ajax = function(settings) {
|
1203
|
+
$.ajax = function( settings ) {
|
1132
1204
|
var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
|
1133
1205
|
port = ( "port" in settings ? settings : $.ajaxSettings ).port;
|
1134
|
-
if (mode
|
1206
|
+
if ( mode === "abort" ) {
|
1135
1207
|
if ( pendingRequests[port] ) {
|
1136
1208
|
pendingRequests[port].abort();
|
1137
1209
|
}
|
1138
|
-
|
1210
|
+
pendingRequests[port] = ajax.apply(this, arguments);
|
1211
|
+
return pendingRequests[port];
|
1139
1212
|
}
|
1140
1213
|
return ajax.apply(this, arguments);
|
1141
1214
|
};
|
1142
1215
|
}
|
1143
|
-
}
|
1144
|
-
|
1145
|
-
// provides cross-browser focusin and focusout events
|
1146
|
-
// IE has native support, in other browsers, use event caputuring (neither bubbles)
|
1216
|
+
}(jQuery));
|
1147
1217
|
|
1148
1218
|
// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
|
1149
1219
|
// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
|
1150
|
-
|
1151
|
-
// only implement if not provided by jQuery core (since 1.4)
|
1152
|
-
// TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
|
1153
|
-
if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
|
1154
|
-
$.each({
|
1155
|
-
focus: 'focusin',
|
1156
|
-
blur: 'focusout'
|
1157
|
-
}, function( original, fix ){
|
1158
|
-
$.event.special[fix] = {
|
1159
|
-
setup:function() {
|
1160
|
-
this.addEventListener( original, handler, true );
|
1161
|
-
},
|
1162
|
-
teardown:function() {
|
1163
|
-
this.removeEventListener( original, handler, true );
|
1164
|
-
},
|
1165
|
-
handler: function(e) {
|
1166
|
-
arguments[0] = $.event.fix(e);
|
1167
|
-
arguments[0].type = fix;
|
1168
|
-
return $.event.handle.apply(this, arguments);
|
1169
|
-
}
|
1170
|
-
};
|
1171
|
-
function handler(e) {
|
1172
|
-
e = $.event.fix(e);
|
1173
|
-
e.type = fix;
|
1174
|
-
return $.event.handle.call(this, e);
|
1175
|
-
}
|
1176
|
-
});
|
1177
|
-
};
|
1220
|
+
(function($) {
|
1178
1221
|
$.extend($.fn, {
|
1179
|
-
validateDelegate: function(delegate, type, handler) {
|
1180
|
-
return this.bind(type, function(event) {
|
1222
|
+
validateDelegate: function( delegate, type, handler ) {
|
1223
|
+
return this.bind(type, function( event ) {
|
1181
1224
|
var target = $(event.target);
|
1182
|
-
if (target.is(delegate)) {
|
1225
|
+
if ( target.is(delegate) ) {
|
1183
1226
|
return handler.apply(target, arguments);
|
1184
1227
|
}
|
1185
1228
|
});
|
1186
1229
|
}
|
1187
1230
|
});
|
1188
|
-
}
|
1231
|
+
}(jQuery));
|