mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-20 09:11:40 +01:00
Updated coding style
This commit is contained in:
66
jquery.validate.js
vendored
66
jquery.validate.js
vendored
@@ -18,31 +18,31 @@ $.extend($.fn, {
|
||||
// if nothing is selected, return nothing; can't chain anyway
|
||||
if ( !this.length ) {
|
||||
if ( options && options.debug && window.console ) {
|
||||
console.warn( "nothing selected, can't validate, returning nothing" );
|
||||
console.warn( "Nothing selected, can't validate, returning nothing." );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// check if a validator for this form was already created
|
||||
var validator = $.data(this[0], 'validator');
|
||||
var validator = $.data( this[0], "validator" );
|
||||
if ( validator ) {
|
||||
return validator;
|
||||
}
|
||||
|
||||
// Add novalidate tag if HTML5.
|
||||
this.attr('novalidate', 'novalidate');
|
||||
this.attr( "novalidate", "novalidate" );
|
||||
|
||||
validator = new $.validator( options, this[0] );
|
||||
$.data(this[0], 'validator', validator);
|
||||
$.data( this[0], "validator", validator );
|
||||
|
||||
if ( validator.settings.onsubmit ) {
|
||||
|
||||
this.validateDelegate( ":submit", "click", function(ev) {
|
||||
this.validateDelegate( ":submit", "click", function( event ) {
|
||||
if ( validator.settings.submitHandler ) {
|
||||
validator.submitButton = ev.target;
|
||||
validator.submitButton = event.target;
|
||||
}
|
||||
// allow suppressing validation by adding a cancel class to the submit button
|
||||
if ( $(ev.target).hasClass('cancel') ) {
|
||||
if ( $(event.target).hasClass("cancel") ) {
|
||||
validator.cancelSubmit = true;
|
||||
}
|
||||
});
|
||||
@@ -92,7 +92,7 @@ $.extend($.fn, {
|
||||
},
|
||||
// http://docs.jquery.com/Plugins/Validation/valid
|
||||
valid: function() {
|
||||
if ( $(this[0]).is('form')) {
|
||||
if ( $(this[0]).is("form")) {
|
||||
return this.validate().form();
|
||||
} else {
|
||||
var valid = true;
|
||||
@@ -118,7 +118,7 @@ $.extend($.fn, {
|
||||
var element = this[0];
|
||||
|
||||
if ( command ) {
|
||||
var settings = $.data(element.form, 'validator').settings;
|
||||
var settings = $.data(element.form, "validator").settings;
|
||||
var staticRules = settings.rules;
|
||||
var existingRules = $.validator.staticRules(element);
|
||||
switch(command) {
|
||||
@@ -234,7 +234,7 @@ $.extend($.validator, {
|
||||
}
|
||||
},
|
||||
onkeyup: function( element, event ) {
|
||||
if ( event.which === 9 && this.elementValue(element) === '' ) {
|
||||
if ( event.which === 9 && this.elementValue(element) === "" ) {
|
||||
return;
|
||||
} else if ( element.name in this.submitted || element === this.lastElement ) {
|
||||
this.element(element);
|
||||
@@ -251,14 +251,14 @@ $.extend($.validator, {
|
||||
}
|
||||
},
|
||||
highlight: function( element, errorClass, validClass ) {
|
||||
if (element.type === 'radio') {
|
||||
if ( element.type === "radio" ) {
|
||||
this.findByName(element.name).addClass(errorClass).removeClass(validClass);
|
||||
} else {
|
||||
$(element).addClass(errorClass).removeClass(validClass);
|
||||
}
|
||||
},
|
||||
unhighlight: function( element, errorClass, validClass ) {
|
||||
if (element.type === 'radio') {
|
||||
if ( element.type === "radio" ) {
|
||||
this.findByName(element.name).removeClass(errorClass).addClass(validClass);
|
||||
} else {
|
||||
$(element).removeClass(errorClass).addClass(validClass);
|
||||
@@ -490,7 +490,7 @@ $.extend($.validator, {
|
||||
},
|
||||
|
||||
errors: function() {
|
||||
var errorClass = this.settings.errorClass.replace(' ', '.');
|
||||
var errorClass = this.settings.errorClass.replace(" ", ".");
|
||||
return $(this.settings.errorElement + "." + errorClass, this.errorContext);
|
||||
},
|
||||
|
||||
@@ -514,14 +514,14 @@ $.extend($.validator, {
|
||||
},
|
||||
|
||||
elementValue: function( element ) {
|
||||
var type = $(element).attr('type'),
|
||||
var type = $(element).attr("type"),
|
||||
val = $(element).val();
|
||||
|
||||
if ( type === 'radio' || type === 'checkbox' ) {
|
||||
return $('input[name="' + $(element).attr('name') + '"]:checked').val();
|
||||
if ( type === "radio" || type === "checkbox" ) {
|
||||
return $("input[name='" + $(element).attr("name") + "']:checked").val();
|
||||
}
|
||||
|
||||
if ( typeof val === 'string' ) {
|
||||
if ( typeof val === "string" ) {
|
||||
return val.replace(/\r/g, "");
|
||||
}
|
||||
return val;
|
||||
@@ -560,7 +560,7 @@ $.extend($.validator, {
|
||||
}
|
||||
} catch(e) {
|
||||
if ( this.settings.debug && window.console ) {
|
||||
console.log("exception occured when checking element " + element.id + ", check the '" + rule.method + "' method", e);
|
||||
console.log( "Exception occured when checking element " + element.id + ", check the '" + rule.method + "' method.", e );
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@@ -577,7 +577,7 @@ $.extend($.validator, {
|
||||
// return the custom message for the given element and validation method
|
||||
// specified in the element's HTML5 data attribute
|
||||
customDataMessage: function( element, method ) {
|
||||
return $(element).data('msg-' + method.toLowerCase()) || (element.attributes && $(element).attr('data-msg-' + method.toLowerCase()));
|
||||
return $(element).data("msg-" + method.toLowerCase()) || (element.attributes && $(element).attr("data-msg-" + method.toLowerCase()));
|
||||
},
|
||||
|
||||
// return the custom message for the given element name and validation method
|
||||
@@ -613,7 +613,7 @@ $.extend($.validator, {
|
||||
if ( typeof message === "function" ) {
|
||||
message = message.call(this, rule.parameters, element);
|
||||
} else if (theregex.test(message)) {
|
||||
message = $.validator.format(message.replace(theregex, '{$1}'), rule.parameters);
|
||||
message = $.validator.format(message.replace(theregex, "{$1}"), rule.parameters);
|
||||
}
|
||||
this.errorList.push({
|
||||
message: message,
|
||||
@@ -711,7 +711,7 @@ $.extend($.validator, {
|
||||
errorsFor: function( element ) {
|
||||
var name = this.idOrName(element);
|
||||
return this.errors().filter(function() {
|
||||
return $(this).attr('for') === name;
|
||||
return $(this).attr("for") === name;
|
||||
});
|
||||
},
|
||||
|
||||
@@ -732,16 +732,16 @@ $.extend($.validator, {
|
||||
},
|
||||
|
||||
findByName: function( name ) {
|
||||
return $(this.currentForm).find('[name="' + name + '"]');
|
||||
return $(this.currentForm).find("[name='" + name + "']");
|
||||
},
|
||||
|
||||
getLength: function( value, element ) {
|
||||
switch( element.nodeName.toLowerCase() ) {
|
||||
case 'select':
|
||||
case "select":
|
||||
return $("option:selected", element).length;
|
||||
case 'input':
|
||||
case "input":
|
||||
if ( this.checkable( element) ) {
|
||||
return this.findByName(element.name).filter(':checked').length;
|
||||
return this.findByName(element.name).filter(":checked").length;
|
||||
}
|
||||
}
|
||||
return value.length;
|
||||
@@ -822,9 +822,9 @@ $.extend($.validator, {
|
||||
|
||||
classRules: function( element ) {
|
||||
var rules = {};
|
||||
var classes = $(element).attr('class');
|
||||
var classes = $(element).attr("class");
|
||||
if ( classes ) {
|
||||
$.each(classes.split(' '), function() {
|
||||
$.each(classes.split(" "), function() {
|
||||
if ( this in $.validator.classRuleSettings ) {
|
||||
$.extend(rules, $.validator.classRuleSettings[this]);
|
||||
}
|
||||
@@ -841,7 +841,7 @@ $.extend($.validator, {
|
||||
var value;
|
||||
|
||||
// support for <input required> in both html5 and older browsers
|
||||
if (method === 'required') {
|
||||
if ( method === "required" ) {
|
||||
value = $element.get(0).getAttribute(method);
|
||||
// Some browsers return an empty string for the required attribute
|
||||
// and non-HTML5 browsers might have required="" markup
|
||||
@@ -873,7 +873,7 @@ $.extend($.validator, {
|
||||
var method, value,
|
||||
rules = {}, $element = $(element);
|
||||
for (method in $.validator.methods) {
|
||||
value = $element.data('rule-' + method.toLowerCase());
|
||||
value = $element.data("rule-" + method.toLowerCase());
|
||||
if ( value !== undefined ) {
|
||||
rules[method] = value;
|
||||
}
|
||||
@@ -883,7 +883,7 @@ $.extend($.validator, {
|
||||
|
||||
staticRules: function( element ) {
|
||||
var rules = {};
|
||||
var validator = $.data(element.form, 'validator');
|
||||
var validator = $.data(element.form, "validator");
|
||||
if ( validator.settings.rules ) {
|
||||
rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
|
||||
}
|
||||
@@ -922,17 +922,17 @@ $.extend($.validator, {
|
||||
});
|
||||
|
||||
// clean number parameters
|
||||
$.each(['minlength', 'maxlength', 'min', 'max'], function() {
|
||||
$.each(["minlength", "maxlength", "min", "max"], function() {
|
||||
if ( rules[this] ) {
|
||||
rules[this] = Number(rules[this]);
|
||||
}
|
||||
});
|
||||
$.each(['rangelength', 'range'], function() {
|
||||
$.each(["rangelength", "range"], function() {
|
||||
var parts;
|
||||
if ( rules[this] ) {
|
||||
if ( $.isArray(rules[this]) ) {
|
||||
rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
|
||||
} else if (typeof rules[this] === 'string') {
|
||||
} else if ( typeof rules[this] === "string" ) {
|
||||
parts = rules[this].split(/[\s,]+/);
|
||||
rules[this] = [Number(parts[0]), Number(parts[1])];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user