mirror of
https://github.com/jquery-validation/jquery-validation.git
synced 2025-12-20 09:11:40 +01:00
JSHint: Remove unused parameters
- Fix double quoting in mockjax response to use doublequotes again
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
|
* Código de identificación fiscal ( CIF ) is the tax identification code for Spanish legal entities
|
||||||
* Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
|
* Further rules can be found in Spanish on http://es.wikipedia.org/wiki/C%C3%B3digo_de_identificaci%C3%B3n_fiscal
|
||||||
*/
|
*/
|
||||||
jQuery.validator.addMethod( "cifES", function( value, element ) {
|
jQuery.validator.addMethod( "cifES", function( value ) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var sum,
|
var sum,
|
||||||
|
|||||||
@@ -27,9 +27,9 @@
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
jQuery.validator.addMethod("currency", function(value, element, param) {
|
jQuery.validator.addMethod("currency", function(value, element, param) {
|
||||||
var paramType = typeof param === "string",
|
var isParamString = typeof param === "string",
|
||||||
symbol = paramType ? param : param[0],
|
symbol = isParamString ? param : param[0],
|
||||||
soft = paramType ? true : param[1],
|
soft = isParamString ? true : param[1],
|
||||||
regex;
|
regex;
|
||||||
|
|
||||||
symbol = symbol.replace(/,/g, "");
|
symbol = symbol.replace(/,/g, "");
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
jQuery.validator.addMethod("ipv4", function(value, element, param) {
|
jQuery.validator.addMethod("ipv4", function(value, element) {
|
||||||
return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value);
|
return this.optional(element) || /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i.test(value);
|
||||||
}, "Please enter a valid IP v4 address.");
|
}, "Please enter a valid IP v4 address.");
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
jQuery.validator.addMethod("ipv6", function(value, element, param) {
|
jQuery.validator.addMethod("ipv6", function(value, element) {
|
||||||
return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value);
|
return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value);
|
||||||
}, "Please enter a valid IP v6 address.");
|
}, "Please enter a valid IP v6 address.");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
|
* The número de identidad de extranjero ( NIE )is a code used to identify the non-nationals in Spain
|
||||||
*/
|
*/
|
||||||
jQuery.validator.addMethod( "nieES", function( value, element ) {
|
jQuery.validator.addMethod( "nieES", function( value ) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
value = value.toUpperCase();
|
value = value.toUpperCase();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
|
* The Número de Identificación Fiscal ( NIF ) is the way tax identification used in Spain for individuals
|
||||||
*/
|
*/
|
||||||
jQuery.validator.addMethod( "nifES", function( value, element ) {
|
jQuery.validator.addMethod( "nifES", function( value ) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
value = value.toUpperCase();
|
value = value.toUpperCase();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// same as url, but TLD is optional
|
// same as url, but TLD is optional
|
||||||
jQuery.validator.addMethod("url2", function(value, element, param) {
|
jQuery.validator.addMethod("url2", function(value, element) {
|
||||||
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]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
|
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]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
|
||||||
}, jQuery.validator.messages.url);
|
}, jQuery.validator.messages.url);
|
||||||
|
|||||||
@@ -238,7 +238,7 @@ $.extend($.validator, {
|
|||||||
onsubmit: true,
|
onsubmit: true,
|
||||||
ignore: ":hidden",
|
ignore: ":hidden",
|
||||||
ignoreTitle: false,
|
ignoreTitle: false,
|
||||||
onfocusin: function( element, event ) {
|
onfocusin: function( element ) {
|
||||||
this.lastActive = element;
|
this.lastActive = element;
|
||||||
|
|
||||||
// hide error label and remove error class on focus if enabled
|
// hide error label and remove error class on focus if enabled
|
||||||
@@ -249,7 +249,7 @@ $.extend($.validator, {
|
|||||||
this.addWrapper(this.errorsFor(element)).hide();
|
this.addWrapper(this.errorsFor(element)).hide();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onfocusout: function( element, event ) {
|
onfocusout: function( element ) {
|
||||||
if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
|
if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
|
||||||
this.element(element);
|
this.element(element);
|
||||||
}
|
}
|
||||||
@@ -261,7 +261,7 @@ $.extend($.validator, {
|
|||||||
this.element(element);
|
this.element(element);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onclick: function( element, event ) {
|
onclick: function( element ) {
|
||||||
// click on selects, radiobuttons and checkboxes
|
// click on selects, radiobuttons and checkboxes
|
||||||
if ( element.name in this.submitted ) {
|
if ( element.name in this.submitted ) {
|
||||||
this.element(element);
|
this.element(element);
|
||||||
@@ -462,6 +462,7 @@ $.extend($.validator, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
objectLength: function( obj ) {
|
objectLength: function( obj ) {
|
||||||
|
/* jshint unused: false */
|
||||||
var count = 0;
|
var count = 0;
|
||||||
for ( var i in obj ) {
|
for ( var i in obj ) {
|
||||||
count++;
|
count++;
|
||||||
@@ -795,7 +796,7 @@ $.extend($.validator, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
dependTypes: {
|
dependTypes: {
|
||||||
"boolean": function( param, element ) {
|
"boolean": function( param ) {
|
||||||
return param;
|
return param;
|
||||||
},
|
},
|
||||||
"string": function( param, element ) {
|
"string": function( param, element ) {
|
||||||
|
|||||||
@@ -386,7 +386,8 @@ test("remote", function() {
|
|||||||
test("remote, customized ajax options", function() {
|
test("remote, customized ajax options", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
stop();
|
stop();
|
||||||
var v = $("#userForm").validate({
|
|
||||||
|
$("#userForm").validate({
|
||||||
rules: {
|
rules: {
|
||||||
username: {
|
username: {
|
||||||
required: true,
|
required: true,
|
||||||
@@ -436,10 +437,12 @@ test("remote extensions", function() {
|
|||||||
});
|
});
|
||||||
$(document).ajaxStop(function() {
|
$(document).ajaxStop(function() {
|
||||||
$(document).unbind("ajaxStop");
|
$(document).unbind("ajaxStop");
|
||||||
equal( 1, v.size(), "There must be one error" );
|
if ( v.size() !== 0 ) {
|
||||||
|
ok( "There must be one error" );
|
||||||
equal( v.errorList[0].message, "asdf is already taken, please try something else" );
|
equal( v.errorList[0].message, "asdf is already taken, please try something else" );
|
||||||
v.element(e);
|
v.element(e);
|
||||||
equal( v.errorList[0].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );
|
equal( v.errorList[0].message, "asdf is already taken, please try something else", "message doesn't change on revalidation" );
|
||||||
|
}
|
||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
|
strictEqual( v.element(e), false, "invalid element, nothing entered yet" );
|
||||||
@@ -1168,13 +1171,13 @@ test("rangeWords", function(){
|
|||||||
|
|
||||||
test("currency", function() { // Works with any symbol
|
test("currency", function() { // Works with any symbol
|
||||||
var method = methodTest( "currency" );
|
var method = methodTest( "currency" );
|
||||||
ok( method( "£9", "£"), "Valid currency" );
|
ok( method( "£9", "£"), "Symbol no decimal" );
|
||||||
ok( method( "£9.9", "£"), "Valid currency" );
|
ok( method( "£9.9", "£"), "£, one decimal" );
|
||||||
ok( method( "£9.99", "£"), "Valid currency" );
|
ok( method( "£9.99", "£"), "£, two decimal" );
|
||||||
ok( method( "£9.90", "£"), "Valid currency" );
|
ok( method( "£9.90", "£"), "Valid currency" );
|
||||||
ok( method( "£9,999.9", "£"), "Valid currency" );
|
ok( method( "£9,999.9", "£"), "£, thousand, comma separator, one decimal" );
|
||||||
ok( method( "£9,999.99", "£"), "Valid currency" );
|
ok( method( "£9,999.99", "£"), "£, thousand, comma separator, two decimal" );
|
||||||
ok( method( "£9,999,999.9", "£"), "Valid currency" );
|
ok( method( "£9,999,999.9", "£"), "£, million, comma separators, one decimal" );
|
||||||
ok( method( "9", ["£", false]), "Valid currency" );
|
ok( method( "9", ["£", false]), "Valid currency" );
|
||||||
ok( method( "9.9", ["£", false]), "Valid currency" );
|
ok( method( "9.9", ["£", false]), "Valid currency" );
|
||||||
ok( method( "9.99", ["£", false]), "Valid currency" );
|
ok( method( "9.99", ["£", false]), "Valid currency" );
|
||||||
|
|||||||
@@ -2,39 +2,49 @@ module("rules");
|
|||||||
|
|
||||||
test("rules() - internal - input", function() {
|
test("rules() - internal - input", function() {
|
||||||
var element = $("#firstname");
|
var element = $("#firstname");
|
||||||
var v = $("#testForm1").validate();
|
|
||||||
|
$("#testForm1").validate();
|
||||||
|
|
||||||
deepEqual( element.rules(), { required: true, minlength: 2 } );
|
deepEqual( element.rules(), { required: true, minlength: 2 } );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rules(), ignore method:false", function() {
|
test("rules(), ignore method:false", function() {
|
||||||
var element = $("#firstnamec");
|
var element = $("#firstnamec");
|
||||||
var v = $("#testForm1clean").validate({
|
|
||||||
|
$("#testForm1clean").validate({
|
||||||
rules: {
|
rules: {
|
||||||
firstname: { required: false, minlength: 2 }
|
firstname: { required: false, minlength: 2 }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual( element.rules(), { minlength: 2 } );
|
deepEqual( element.rules(), { minlength: 2 } );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rules() HTML5 required (no value)", function() {
|
test("rules() HTML5 required (no value)", function() {
|
||||||
var element = $("#testForm11text1");
|
var element = $("#testForm11text1");
|
||||||
var v = $("#testForm11").validate();
|
|
||||||
|
$("#testForm11").validate();
|
||||||
|
|
||||||
deepEqual( element.rules(), { required: true } );
|
deepEqual( element.rules(), { required: true } );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rules() - internal - select", function() {
|
test("rules() - internal - select", function() {
|
||||||
var element = $("#meal");
|
var element = $("#meal");
|
||||||
var v = $("#testForm3").validate();
|
|
||||||
|
$("#testForm3").validate();
|
||||||
|
|
||||||
deepEqual( element.rules(), {required: true} );
|
deepEqual( element.rules(), {required: true} );
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rules() - external", function() {
|
test("rules() - external", function() {
|
||||||
var element = $("#text1");
|
var element = $("#text1");
|
||||||
var v = $("#form").validate({
|
|
||||||
|
$("#form").validate({
|
||||||
rules: {
|
rules: {
|
||||||
action: {date: true, min: 5}
|
action: {date: true, min: 5}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual( element.rules(), {date: true, min: 5} );
|
deepEqual( element.rules(), {date: true, min: 5} );
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -61,13 +71,16 @@ test("rules() - external - complete form", function() {
|
|||||||
|
|
||||||
test("rules() - internal - input", function() {
|
test("rules() - internal - input", function() {
|
||||||
var element = $("#form8input");
|
var element = $("#form8input");
|
||||||
var v = $("#testForm8").validate();
|
|
||||||
|
$("#testForm8").validate();
|
||||||
|
|
||||||
deepEqual( element.rules(), {required: true, number: true, rangelength: [2, 8]});
|
deepEqual( element.rules(), {required: true, number: true, rangelength: [2, 8]});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("rules(), merge min/max to range, minlength/maxlength to rangelength", function() {
|
test("rules(), merge min/max to range, minlength/maxlength to rangelength", function() {
|
||||||
jQuery.validator.autoCreateRanges = true;
|
jQuery.validator.autoCreateRanges = true;
|
||||||
var v = $("#testForm1clean").validate({
|
|
||||||
|
$("#testForm1clean").validate({
|
||||||
rules: {
|
rules: {
|
||||||
firstname: {
|
firstname: {
|
||||||
min: 5,
|
min: 5,
|
||||||
@@ -79,6 +92,7 @@ test("rules(), merge min/max to range, minlength/maxlength to rangelength", func
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual( $("#firstnamec").rules(), {range: [5, 12]});
|
deepEqual( $("#firstnamec").rules(), {range: [5, 12]});
|
||||||
|
|
||||||
deepEqual( $("#lastnamec").rules(), {rangelength: [2, 8]} );
|
deepEqual( $("#lastnamec").rules(), {rangelength: [2, 8]} );
|
||||||
@@ -91,7 +105,7 @@ test("rules(), guarantee that required is at front", function() {
|
|||||||
$("#subformRequired").validate();
|
$("#subformRequired").validate();
|
||||||
function flatRules(element) {
|
function flatRules(element) {
|
||||||
var result = [];
|
var result = [];
|
||||||
jQuery.each($(element).rules(), function(key, value) { result.push(key); });
|
jQuery.each($(element).rules(), function(key) { result.push(key); });
|
||||||
return result.join(" ");
|
return result.join(" ");
|
||||||
}
|
}
|
||||||
equal( "required minlength", flatRules("#firstname") );
|
equal( "required minlength", flatRules("#firstname") );
|
||||||
@@ -115,7 +129,8 @@ test("rules(), guarantee that required is at front", function() {
|
|||||||
|
|
||||||
test("rules(), evaluate dynamic parameters", function() {
|
test("rules(), evaluate dynamic parameters", function() {
|
||||||
expect(2);
|
expect(2);
|
||||||
var v = $("#testForm1clean").validate({
|
|
||||||
|
$("#testForm1clean").validate({
|
||||||
rules: {
|
rules: {
|
||||||
firstname: {
|
firstname: {
|
||||||
min: function(element) {
|
min: function(element) {
|
||||||
@@ -125,6 +140,7 @@ test("rules(), evaluate dynamic parameters", function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual( $("#firstnamec").rules(), {min:12});
|
deepEqual( $("#firstnamec").rules(), {min:12});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -136,7 +152,8 @@ test("rules(), class and attribute combinations", function() {
|
|||||||
$.validator.addMethod("customMethod2", function() {
|
$.validator.addMethod("customMethod2", function() {
|
||||||
return false;
|
return false;
|
||||||
}, "");
|
}, "");
|
||||||
var v = $("#v2").validate({
|
|
||||||
|
$("#v2").validate({
|
||||||
rules: {
|
rules: {
|
||||||
"v2-i7": {
|
"v2-i7": {
|
||||||
required: true,
|
required: true,
|
||||||
@@ -145,6 +162,7 @@ test("rules(), class and attribute combinations", function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual( $("#v2-i1").rules(), { required: true });
|
deepEqual( $("#v2-i1").rules(), { required: true });
|
||||||
deepEqual( $("#v2-i2").rules(), { required: true, email: true });
|
deepEqual( $("#v2-i2").rules(), { required: true, email: true });
|
||||||
deepEqual( $("#v2-i3").rules(), { url: true });
|
deepEqual( $("#v2-i3").rules(), { url: true });
|
||||||
@@ -215,11 +233,13 @@ test("rules(), add and remove", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("rules(), add and remove static rules", function() {
|
test("rules(), add and remove static rules", function() {
|
||||||
var v = $("#testForm1clean").validate({
|
|
||||||
|
$("#testForm1clean").validate({
|
||||||
rules: {
|
rules: {
|
||||||
firstname: "required date"
|
firstname: "required date"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
deepEqual( $("#firstnamec").rules(), { required: true, date: true } );
|
deepEqual( $("#firstnamec").rules(), { required: true, date: true } );
|
||||||
|
|
||||||
$("#firstnamec").rules("remove", "date");
|
$("#firstnamec").rules("remove", "date");
|
||||||
|
|||||||
56
test/test.js
56
test/test.js
@@ -20,7 +20,7 @@ $.mockjax({
|
|||||||
$.mockjax({
|
$.mockjax({
|
||||||
url: "users2.php",
|
url: "users2.php",
|
||||||
data: { username: "asdf"},
|
data: { username: "asdf"},
|
||||||
responseText: "'asdf is already taken, please try something else'",
|
responseText: "\"asdf is already taken, please try something else\"",
|
||||||
responseStatus: 200,
|
responseStatus: 200,
|
||||||
responseTime: 1
|
responseTime: 1
|
||||||
});
|
});
|
||||||
@@ -95,7 +95,7 @@ test("addMethod", function() {
|
|||||||
|
|
||||||
test("addMethod2", function() {
|
test("addMethod2", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
$.validator.addMethod("complicatedPassword", function(value, element, param) {
|
$.validator.addMethod("complicatedPassword", function(value, element) {
|
||||||
return this.optional(element) || /\D/.test(value) && /\d/.test(value);
|
return this.optional(element) || /\D/.test(value) && /\d/.test(value);
|
||||||
}, "Your password must contain at least one number and one letter");
|
}, "Your password must contain at least one number and one letter");
|
||||||
var v = jQuery("#form").validate({
|
var v = jQuery("#form").validate({
|
||||||
@@ -103,8 +103,7 @@ test("addMethod2", function() {
|
|||||||
action: { complicatedPassword: true }
|
action: { complicatedPassword: true }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var rule = $.validator.methods.complicatedPassword,
|
var e = $("#text1")[0];
|
||||||
e = $("#text1")[0];
|
|
||||||
e.value = "";
|
e.value = "";
|
||||||
strictEqual( v.element(e), true, "Rule is optional, valid" );
|
strictEqual( v.element(e), true, "Rule is optional, valid" );
|
||||||
equal( 0, v.size() );
|
equal( 0, v.size() );
|
||||||
@@ -241,7 +240,6 @@ test("hide(): errorWrapper", function() {
|
|||||||
test("hide(): container", function() {
|
test("hide(): container", function() {
|
||||||
expect(4);
|
expect(4);
|
||||||
var errorLabel = $("#errorContainer");
|
var errorLabel = $("#errorContainer");
|
||||||
var element = $("#testForm3")[0];
|
|
||||||
var v = $("#testForm3").validate({ errorWrapper: "li", errorContainer: $("#errorContainer") });
|
var v = $("#testForm3").validate({ errorWrapper: "li", errorContainer: $("#errorContainer") });
|
||||||
v.form();
|
v.form();
|
||||||
ok( errorLabel.is(":visible"), "Error label visible after validation" );
|
ok( errorLabel.is(":visible"), "Error label visible after validation" );
|
||||||
@@ -293,7 +291,6 @@ test("submitHandler keeps submitting button", function() {
|
|||||||
test("showErrors()", function() {
|
test("showErrors()", function() {
|
||||||
expect( 4 );
|
expect( 4 );
|
||||||
var errorLabel = $("#errorFirstname").hide();
|
var errorLabel = $("#errorFirstname").hide();
|
||||||
var element = $("#firstname")[0];
|
|
||||||
var v = $("#testForm1").validate();
|
var v = $("#testForm1").validate();
|
||||||
ok( errorLabel.is(":hidden") );
|
ok( errorLabel.is(":hidden") );
|
||||||
equal( 0, $("label.error[for=lastname]").size() );
|
equal( 0, $("label.error[for=lastname]").size() );
|
||||||
@@ -618,7 +615,7 @@ test("error containers, with labelcontainer I", function() {
|
|||||||
equal( 2, labelcontainer.find("li").length, "There should be two error lis in the labelcontainer" );
|
equal( 2, labelcontainer.find("li").length, "There should be two error lis in the labelcontainer" );
|
||||||
ok( container.is(":visible"), "Check that the container is visible" );
|
ok( container.is(":visible"), "Check that the container is visible" );
|
||||||
ok( labelcontainer.is(":visible"), "Check that the labelcontainer is visible" );
|
ok( labelcontainer.is(":visible"), "Check that the labelcontainer is visible" );
|
||||||
var labels = labelcontainer.find("label").each(function() {
|
labelcontainer.find("label").each(function() {
|
||||||
ok( $(this).is(":visible"), "Check that each label is visible1" );
|
ok( $(this).is(":visible"), "Check that each label is visible1" );
|
||||||
equal( "li", $(this).parent()[0].tagName.toLowerCase(), "Check that each label is wrapped in an li" );
|
equal( "li", $(this).parent()[0].tagName.toLowerCase(), "Check that each label is wrapped in an li" );
|
||||||
ok( $(this).parent("li").is(":visible"), "Check that each parent li is visible" );
|
ok( $(this).parent("li").is(":visible"), "Check that each parent li is visible" );
|
||||||
@@ -661,7 +658,7 @@ test("errorcontainer, show/hide only on submit", function() {
|
|||||||
|
|
||||||
test("option invalidHandler", function() {
|
test("option invalidHandler", function() {
|
||||||
expect(1);
|
expect(1);
|
||||||
var v = $("#testForm1clean").validate({
|
$("#testForm1clean").validate({
|
||||||
invalidHandler: function() {
|
invalidHandler: function() {
|
||||||
ok( true, "invalid-form event triggered called" );
|
ok( true, "invalid-form event triggered called" );
|
||||||
start();
|
start();
|
||||||
@@ -931,7 +928,7 @@ test("success is called for optional elements with other rules", function() {
|
|||||||
return true;
|
return true;
|
||||||
}, "");
|
}, "");
|
||||||
|
|
||||||
var v = $("#testForm1clean").validate({
|
$("#testForm1clean").validate({
|
||||||
success: function() {
|
success: function() {
|
||||||
ok( true, "success called correctly!" );
|
ok( true, "success called correctly!" );
|
||||||
},
|
},
|
||||||
@@ -1248,7 +1245,7 @@ test("correct checkbox receives the error", function(){
|
|||||||
element.valid();
|
element.valid();
|
||||||
}
|
}
|
||||||
var e1 = $("#check1").attr("checked", false);
|
var e1 = $("#check1").attr("checked", false);
|
||||||
var e2 = $("#check1b").attr("checked", false);
|
$("#check1b").attr("checked", false);
|
||||||
var v = $("#form").find("[type=checkbox]").attr("checked", false).end().validate({
|
var v = $("#form").find("[type=checkbox]").attr("checked", false).end().validate({
|
||||||
rules:{
|
rules:{
|
||||||
check: {
|
check: {
|
||||||
@@ -1332,7 +1329,8 @@ test("ignore hidden elements at start", function(){
|
|||||||
test("Specify error messages through data attributes", function() {
|
test("Specify error messages through data attributes", function() {
|
||||||
var form = $("#dataMessages");
|
var form = $("#dataMessages");
|
||||||
var name = $("#dataMessagesName");
|
var name = $("#dataMessagesName");
|
||||||
var v = form.validate();
|
|
||||||
|
form.validate();
|
||||||
|
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
@@ -1345,10 +1343,10 @@ test("Updates pre-existing label if has error class", function() {
|
|||||||
var form = $("#updateLabel"),
|
var form = $("#updateLabel"),
|
||||||
input = $("#updateLabelInput"),
|
input = $("#updateLabelInput"),
|
||||||
label = $("#targetLabel"),
|
label = $("#targetLabel"),
|
||||||
v = form.validate(),
|
|
||||||
labelsBefore = form.find("label").length,
|
labelsBefore = form.find("label").length,
|
||||||
labelsAfter;
|
labelsAfter;
|
||||||
|
|
||||||
|
form.validate();
|
||||||
input.val("");
|
input.val("");
|
||||||
input.valid();
|
input.valid();
|
||||||
labelsAfter = form.find("label").length;
|
labelsAfter = form.find("label").length;
|
||||||
@@ -1362,8 +1360,8 @@ test("Updates pre-existing label if has error class", function() {
|
|||||||
test("Min date set by attribute", function() {
|
test("Min date set by attribute", function() {
|
||||||
var form = $("#rangesMinDateInvalid");
|
var form = $("#rangesMinDateInvalid");
|
||||||
var name = $("#minDateInvalid");
|
var name = $("#minDateInvalid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1374,8 +1372,8 @@ test("Min date set by attribute", function() {
|
|||||||
test("Max date set by attribute", function() {
|
test("Max date set by attribute", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#maxDateInvalid");
|
var name = $("#maxDateInvalid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1386,8 +1384,8 @@ test("Max date set by attribute", function() {
|
|||||||
test("Min and Max date set by attributes greater", function() {
|
test("Min and Max date set by attributes greater", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeDateInvalidGreater");
|
var name = $("#rangeDateInvalidGreater");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1398,8 +1396,8 @@ test("Min and Max date set by attributes greater", function() {
|
|||||||
test("Min and Max date set by attributes less", function() {
|
test("Min and Max date set by attributes less", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeDateInvalidLess");
|
var name = $("#rangeDateInvalidLess");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1410,8 +1408,8 @@ test("Min and Max date set by attributes less", function() {
|
|||||||
test("Min date set by attribute valid", function() {
|
test("Min date set by attribute valid", function() {
|
||||||
var form = $("#rangeMinDateValid");
|
var form = $("#rangeMinDateValid");
|
||||||
var name = $("#minDateValid");
|
var name = $("#minDateValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1422,8 +1420,8 @@ test("Min date set by attribute valid", function() {
|
|||||||
test("Max date set by attribute valid", function() {
|
test("Max date set by attribute valid", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#maxDateValid");
|
var name = $("#maxDateValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1434,8 +1432,8 @@ test("Max date set by attribute valid", function() {
|
|||||||
test("Min and Max date set by attributes valid", function() {
|
test("Min and Max date set by attributes valid", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeDateValid");
|
var name = $("#rangeDateValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1446,8 +1444,8 @@ test("Min and Max date set by attributes valid", function() {
|
|||||||
test("Min and Max strings set by attributes greater", function() {
|
test("Min and Max strings set by attributes greater", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeTextInvalidGreater");
|
var name = $("#rangeTextInvalidGreater");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1458,8 +1456,8 @@ test("Min and Max strings set by attributes greater", function() {
|
|||||||
test("Min and Max strings set by attributes less", function() {
|
test("Min and Max strings set by attributes less", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeTextInvalidLess");
|
var name = $("#rangeTextInvalidLess");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1470,8 +1468,8 @@ test("Min and Max strings set by attributes less", function() {
|
|||||||
test("Min and Max strings set by attributes valid", function() {
|
test("Min and Max strings set by attributes valid", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeTextValid");
|
var name = $("#rangeTextValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1498,8 +1496,8 @@ test( "calling blur on ignored element", function() {
|
|||||||
test("Min and Max type absent set by attributes greater", function() {
|
test("Min and Max type absent set by attributes greater", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeAbsentInvalidGreater");
|
var name = $("#rangeAbsentInvalidGreater");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1510,8 +1508,8 @@ test("Min and Max type absent set by attributes greater", function() {
|
|||||||
test("Min and Max type absent set by attributes less", function() {
|
test("Min and Max type absent set by attributes less", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeAbsentInvalidLess");
|
var name = $("#rangeAbsentInvalidLess");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1522,8 +1520,8 @@ test("Min and Max type absent set by attributes less", function() {
|
|||||||
test("Min and Max type absent set by attributes valid", function() {
|
test("Min and Max type absent set by attributes valid", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeAbsentValid");
|
var name = $("#rangeAbsentValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1543,8 +1541,8 @@ test("Min and Max range set by attributes valid", function() {
|
|||||||
//
|
//
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeRangeValid");
|
var name = $("#rangeRangeValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1556,8 +1554,8 @@ test("Min and Max range set by attributes valid", function() {
|
|||||||
test("Min and Max number set by attributes valid", function() {
|
test("Min and Max number set by attributes valid", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeNumberValid");
|
var name = $("#rangeNumberValid");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1569,8 +1567,8 @@ test("Min and Max number set by attributes valid", function() {
|
|||||||
test("Min and Max number set by attributes greater", function() {
|
test("Min and Max number set by attributes greater", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeNumberInvalidGreater");
|
var name = $("#rangeNumberInvalidGreater");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
@@ -1582,8 +1580,8 @@ test("Min and Max number set by attributes greater", function() {
|
|||||||
test("Min and Max number set by attributes less", function() {
|
test("Min and Max number set by attributes less", function() {
|
||||||
var form = $("#ranges");
|
var form = $("#ranges");
|
||||||
var name = $("#rangeNumberInvalidLess");
|
var name = $("#rangeNumberInvalidLess");
|
||||||
var v = form.validate();
|
|
||||||
|
|
||||||
|
form.validate();
|
||||||
form.get(0).reset();
|
form.get(0).reset();
|
||||||
name.valid();
|
name.valid();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user