diff --git a/.jscsrc b/.jscsrc index 0e4ae84..850275c 100644 --- a/.jscsrc +++ b/.jscsrc @@ -16,6 +16,7 @@ "requireMultipleVarDecl": "onevar", "disallowTrailingWhitespace": true, "validateQuoteMarks": "\"", + "requireSpacesInsideArrayBrackets": "allButNested", "excludeFiles": [ "node_modules/**", "dist/**" diff --git a/test/error-placement.js b/test/error-placement.js index 29d2e92..4b30ed4 100644 --- a/test/error-placement.js +++ b/test/error-placement.js @@ -7,13 +7,36 @@ test( "elements() order", function() { wrap: "li" }); - deepEqual( v.elements().map( function() { - return $( this ).attr( "id" ); - }).get(), ["order1", "order2", "order3", "order4", "order5", "order6"], "elements must be in document order" ); + deepEqual( + v.elements().map( function() { + return $( this ).attr( "id" ); + }).get(), + [ + "order1", + "order2", + "order3", + "order4", + "order5", + "order6" + ], + "elements must be in document order" + ); + v.form(); - deepEqual( container.children().map( function() { - return $( this ).attr( "id" ); - }).get(), ["order1-error", "order2-error", "order3-error", "order4-error", "order5-error", "order6-error"], "labels in error container must be in document order" ); + deepEqual( + container.children().map( function() { + return $( this ).attr( "id" ); + }).get(), + [ + "order1-error", + "order2-error", + "order3-error", + "order4-error", + "order5-error", + "order6-error" + ], + "labels in error container must be in document order" + ); }); test( "error containers, simple", function() { @@ -33,7 +56,21 @@ test( "error containers, simple", function() { equal( "", container.find( "h3" ).html() ); v.prepareForm(); - v.errorList = [{message:"bar", element: {name:"foo"}}, {message: "necessary", element: {name:"required"}}]; + v.errorList = [ + { + message: "bar", + element: { + name: "foo" + } + }, + { + message: "necessary", + element: { + name: "required" + } + } + ]; + ok( !v.valid(), "form is not valid after adding errors manually" ); v.showErrors(); equal( container.find( ".error:not(input)" ).length, 2, "There should be two error labels" ); @@ -68,7 +105,22 @@ test( "error containers, with labelcontainer I", function() { equal( 0, labelcontainer.find( ".error:not(input)" ).length, "There should be no error labels in the labelcontainer" ); equal( 0, labelcontainer.find( "li" ).length, "There should be no lis labels in the labelcontainer" ); - v.errorList = [{message:"bar", element: {name:"foo"}}, {name: "required", message: "necessary", element: {name:"required"}}]; + v.errorList = [ + { + message: "bar", + element: { + name: "foo" + } + }, + { + name: "required", + message: "necessary", + element: { + name: "required" + } + } + ]; + ok( !v.valid(), "form is not valid after adding errors manually" ); v.showErrors(); equal( 0, container.find( ".error:not(input)" ).length, "There should be no error label in the container" ); @@ -110,7 +162,12 @@ test( "errorcontainer, show/hide only on submit", function() { ok( container.is( ":visible" ), "must be visible" ); $( "#firstname" ).val( "hix" ).keyup(); - $( "#testForm1" ).triggerHandler( "keyup", [jQuery.event.fix({ type: "keyup", target: $( "#firstname" )[0] })]); + $( "#testForm1" ).triggerHandler( "keyup", [ + jQuery.event.fix({ + type: "keyup", + target: $( "#firstname" )[ 0 ] + }) + ]); equal( 1, labelContainer.find( ".error:visible" ).length ); equal( "There are 1 errors in your form.", container.html() ); @@ -122,7 +179,7 @@ test( "test label used as error container", function(assert) { expect( 8 ); var form = $( "#testForm16" ), field = $( "#testForm16text" ); - + form.validate({ errorPlacement: function( error, element ) { // Append error within linked label @@ -130,7 +187,7 @@ test( "test label used as error container", function(assert) { }, errorElement: "span" }); - + ok( !field.valid() ); equal( "Field Label", field.next( "label" ).contents( ":not(span)" ).text(), "container label isn't disrupted" ); assert.hasError(field, "missing"); @@ -147,11 +204,11 @@ test( "test error placed adjacent to descriptive label", function(assert) { expect( 8 ); var form = $( "#testForm16" ), field = $( "#testForm16text" ); - + form.validate({ errorElement: "span" }); - + ok( !field.valid() ); equal( 1, form.find( "label" ).length ); equal( "Field Label", form.find( "label" ).text(), "container label isn't disrupted" ); @@ -168,11 +225,11 @@ test( "test descriptive label used alongside error label", function(assert) { expect( 8 ); var form = $( "#testForm16" ), field = $( "#testForm16text" ); - + form.validate({ errorElement: "label" }); - + ok( !field.valid() ); equal( 1, form.find( "label.title" ).length ); equal( "Field Label", form.find( "label.title" ).text(), "container label isn't disrupted" ); @@ -189,14 +246,14 @@ test( "test custom errorElement", function(assert) { expect( 4 ); var form = $( "#userForm" ), field = $( "#username" ); - + form.validate({ messages: { username: "missing" }, errorElement: "label" }); - + ok( !field.valid() ); assert.hasError( field, "missing", "Field should have error 'missing'" ); field.val( "foo" ); @@ -208,9 +265,9 @@ test( "test existing label used as error element", function(assert) { expect( 4 ); var form = $( "#testForm14" ), field = $( "#testForm14text" ); - - form.validate({errorElement: "label"}); - + + form.validate({ errorElement: "label" }); + ok( !field.valid() ); assert.hasError( field, "required" ); @@ -223,9 +280,9 @@ test( "test existing non-label used as error element", function(assert) { expect( 4 ); var form = $( "#testForm15" ), field = $( "#testForm15text" ); - - form.validate({errorElement: "span"}); - + + form.validate({ errorElement: "span" }); + ok( !field.valid() ); assert.hasError( field ); diff --git a/test/messages.js b/test/messages.js index 17048fd..10b4fde 100644 --- a/test/messages.js +++ b/test/messages.js @@ -11,7 +11,7 @@ test("predefined message not overwritten by addMethod(a, b, undefined)", functio test("group error messages", function() { $.validator.addClassRules({ - requiredDateRange: {required:true, date:true, dateRange:true} + requiredDateRange: { required: true, date: true, dateRange: true } }); $.validator.addMethod("dateRange", function() { return new Date($("#fromDate").val()) < new Date($("#toDate").val()); @@ -57,7 +57,6 @@ test("read messages from metadata", function() { equal( form.find("#testGeneric9").next(".error:not(input)").text(), "email" ); }); - test("read messages from metadata, with meta option specified, but no metadata in there", function() { var form = $("#testForm1clean"); form.validate({ diff --git a/test/methods.js b/test/methods.js index 870288e..de90420 100644 --- a/test/methods.js +++ b/test/methods.js @@ -269,7 +269,7 @@ test("maxlength", function() { test("rangelength", function() { var v = jQuery("#form").validate(), method = $.validator.methods.rangelength, - param = [2, 4], + param = [ 2, 4 ], e = $("#text1, #text2, #text3"); ok( method.call( v, e[0].value, e[0], param), "Valid text input" ); @@ -302,7 +302,7 @@ test("max", function() { test("range", function() { var v = jQuery("#form").validate(), method = $.validator.methods.range, - param = [4,12], + param = [ 4, 12 ], e = $("#value1, #value2, #value3"); ok(!method.call( v, e[0].value, e[0], param), "Invalid text input" ); @@ -420,7 +420,6 @@ asyncTest("remote, customized ajax options", function() { $("#userForm").valid(); }); - asyncTest("remote extensions", function() { expect(5); var e = $("#username"), @@ -492,7 +491,7 @@ asyncTest("remote reset clear old value", function() { url: "echo.php", dataFilter: function(data) { var json = JSON.parse(data); - if(json.username === "asdf") { + if (json.username === "asdf") { return "\"asdf is already taken\""; } return "\"" + true + "\""; @@ -507,14 +506,12 @@ asyncTest("remote reset clear old value", function() { $(document).unbind("ajaxStop"); - $(document).ajaxStop(function() { clearTimeout(waitTimeout); ok( true, "Remote request sent to server" ); start(); }); - v.resetForm(); e.val("asdf"); waitTimeout = setTimeout(function() { @@ -900,11 +897,11 @@ test("maxWords", function() { test("rangeWords", function() { var method = methodTest("rangeWords"); - ok( method( "hello", [0, 2] ), "plain text, valid" ); - ok( method( "hello worlds", [0, 2] ), "plain text, valid" ); - ok( method( "hello world", [0, 2] ), "html, valid" ); - ok(!method( "hello worlds what is up", [0, 2] ), "plain text, invalid" ); - ok(!method( "Hello world hello", [0, 2] ), "html, invalid" ); + ok( method( "hello", [ 0, 2 ] ), "plain text, valid" ); + ok( method( "hello worlds", [ 0, 2 ] ), "plain text, valid" ); + ok( method( "hello world", [ 0, 2 ] ), "html, valid" ); + ok(!method( "hello worlds what is up", [ 0, 2 ] ), "plain text, invalid" ); + ok(!method( "Hello world hello", [ 0, 2 ] ), "html, invalid" ); }); test("pattern", function() { @@ -993,71 +990,71 @@ function fillFormWithValuesAndExpect(formSelector, inputValues, expected) { test("require_from_group", function() { $("#productInfo").validate({ rules: { - partnumber: {require_from_group: [2,".productInfo"]}, - description: {require_from_group: [2,".productInfo"]}, - discount: {require_from_group: [2,".productInfo"]} + partnumber: { require_from_group: [ 2,".productInfo" ] }, + description: { require_from_group: [ 2,".productInfo" ] }, + discount: { require_from_group: [ 2,".productInfo" ] } } }); fillFormWithValuesAndExpect("#productInfo", [], false); - fillFormWithValuesAndExpect("#productInfo", [123], false); + fillFormWithValuesAndExpect("#productInfo", [ 123 ], false); $("#productInfo input[type='checkbox']").attr("checked", "checked"); - fillFormWithValuesAndExpect("#productInfo", [123], true); + fillFormWithValuesAndExpect("#productInfo", [ 123 ], true); $("#productInfo input[type='checkbox']").removeAttr("checked"); - fillFormWithValuesAndExpect("#productInfo", [123, "widget"], true); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red"], true); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red"], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget" ], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red" ], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red" ], true); }); test("require_from_group preserve other rules", function() { $("#productInfo").validate({ rules: { - partnumber: {require_from_group: [2,".productInfo"]}, - description: {require_from_group: [2,".productInfo"]}, - color: {require_from_group: [2,".productInfo"]}, - supplier: {required: true} + partnumber: { require_from_group: [ 2,".productInfo" ] }, + description: { require_from_group: [ 2,".productInfo" ] }, + color: { require_from_group: [ 2,".productInfo" ] }, + supplier: { required: true } } }); fillFormWithValuesAndExpect("#productInfo", [], false); - fillFormWithValuesAndExpect("#productInfo", [123], false); - fillFormWithValuesAndExpect("#productInfo", [123, "widget"], false); - fillFormWithValuesAndExpect("#productInfo", ["", "", "", "Acme"], false); - fillFormWithValuesAndExpect("#productInfo", [123, "", "", "Acme"], false); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "", "Acme"], true); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red", "Acme"], true); + fillFormWithValuesAndExpect("#productInfo", [ 123 ], false); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget" ], false); + fillFormWithValuesAndExpect("#productInfo", [ "", "", "", "Acme" ], false); + fillFormWithValuesAndExpect("#productInfo", [ 123, "", "", "Acme" ], false); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "", "Acme" ], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red", "Acme" ], true); }); test("skip_or_fill_minimum", function() { $("#productInfo").validate({ rules: { - partnumber: {skip_or_fill_minimum: [2,".productInfo"]}, - description: {skip_or_fill_minimum: [2,".productInfo"]}, - color: {skip_or_fill_minimum: [2,".productInfo"]} + partnumber: { skip_or_fill_minimum: [ 2,".productInfo" ] }, + description: { skip_or_fill_minimum: [ 2,".productInfo" ] }, + color: { skip_or_fill_minimum: [ 2,".productInfo" ] } } }); fillFormWithValuesAndExpect("#productInfo", [], true); - fillFormWithValuesAndExpect("#productInfo", [123], false); - fillFormWithValuesAndExpect("#productInfo", [123, "widget"], true); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red"], true); + fillFormWithValuesAndExpect("#productInfo", [ 123 ], false); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget" ], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red" ], true); }); test("skip_or_fill_minimum preserve other rules", function() { $("#productInfo").validate({ rules: { - partnumber: {skip_or_fill_minimum: [2,".productInfo"]}, - description: {skip_or_fill_minimum: [2,".productInfo"]}, - color: {skip_or_fill_minimum: [2,".productInfo"]}, - supplier: {required: true} + partnumber: { skip_or_fill_minimum: [ 2,".productInfo" ] }, + description: { skip_or_fill_minimum: [ 2,".productInfo" ] }, + color: { skip_or_fill_minimum: [ 2,".productInfo" ] }, + supplier: { required: true } } }); fillFormWithValuesAndExpect("#productInfo", [], false); - fillFormWithValuesAndExpect("#productInfo", ["", "", "", "Acme"], true); - fillFormWithValuesAndExpect("#productInfo", [123, "", "", "Acme"], false); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "", "Acme"], true); - fillFormWithValuesAndExpect("#productInfo", [123, "widget", "red", "Acme"], true); + fillFormWithValuesAndExpect("#productInfo", [ "", "", "", "Acme" ], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "", "", "Acme" ], false); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "", "Acme" ], true); + fillFormWithValuesAndExpect("#productInfo", [ 123, "widget", "red", "Acme" ], true); }); test("zipcodeUS", function() { @@ -1166,7 +1163,7 @@ test("cifES", function() { ok(!method( "B-43.522.192" ), "CIF invalid: dots and dash" ); }); -test("maxWords", function(){ +test("maxWords", function() { var method = methodTest("maxWords"), maxWords = 6; @@ -1178,7 +1175,7 @@ test("maxWords", function(){ ok(!method( "