]> source.dussan.org Git - jquery.git/commitdiff
Coerce all array values to strings before comparison in val(). Fixes bug #7123. 38/head
authorColin Snover <github.com@zetafleet.com>
Sat, 9 Oct 2010 03:48:06 +0000 (22:48 -0500)
committerColin Snover <github.com@zetafleet.com>
Sat, 9 Oct 2010 03:48:06 +0000 (22:48 -0500)
src/attributes.js
test/unit/attributes.js

index ec4841bd3f4f27d271f01a5388e8fd39ca97e2e0..147c353f4219a14cce5a9da3674818fef583b18f 100644 (file)
@@ -215,6 +215,10 @@ jQuery.fn.extend({
                                val = "";
                        } else if ( typeof val === "number" ) {
                                val += "";
+                       } else if ( jQuery.isArray(val) ) {
+                               val = jQuery.map(val, function (value) {
+                                       return value == null ? "" : value + "";
+                               });
                        }
 
                        if ( jQuery.isArray(val) && rradiocheck.test( this.type ) ) {
index a483195a4cbb16b641b574d05814d57721558be0..c6007aacc8ab21df33757f1b2e970199baa3af18 100644 (file)
@@ -409,7 +409,19 @@ test("val(String/Number)", function() {
 
 test("val(Function)", function() {
        testVal(functionReturningObj);
-})
+});
+
+test( "val(Array of Numbers) (Bug #7123)", function() {
+       expect(4);
+       jQuery('#form').append('<input type="checkbox" name="arrayTest" value="1" /><input type="checkbox" name="arrayTest" value="2" /><input type="checkbox" name="arrayTest" value="3" checked="checked" /><input type="checkbox" name="arrayTest" value="4" />');
+       var elements = jQuery('input[name=arrayTest]').val([ 1, 2 ]);
+       ok( elements[0].checked, "First element was checked" );
+       ok( elements[1].checked, "Second element was checked" );
+       ok( !elements[2].checked, "Third element was unchecked" );
+       ok( !elements[3].checked, "Fourth element remained unchecked" );
+       
+       elements.remove();
+});
 
 test("val(Function) with incoming value", function() {
        expect(10);