diff options
author | jeresig <jeresig@gmail.com> | 2009-12-22 01:18:49 -0500 |
---|---|---|
committer | jeresig <jeresig@gmail.com> | 2009-12-22 01:18:49 -0500 |
commit | f298cce100c6fe23840ac95e66aaea9cb2bfb447 (patch) | |
tree | 6df53cdd21ec09555efbf9b05a808a326fc0696b | |
parent | 261b7efb5f86a5c9a3de8434f3cad858101e4249 (diff) | |
download | jquery-f298cce100c6fe23840ac95e66aaea9cb2bfb447.tar.gz jquery-f298cce100c6fe23840ac95e66aaea9cb2bfb447.zip |
Made sure that the .val() logic for setting radios and checkboxes was correct. Fixes #5698.
-rw-r--r-- | src/attributes.js | 2 | ||||
-rw-r--r-- | test/unit/manipulation.js | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/attributes.js b/src/attributes.js index 91a0fe176..eecf90fa9 100644 --- a/src/attributes.js +++ b/src/attributes.js @@ -158,7 +158,7 @@ jQuery.fn.extend({ } if ( jQuery.isArray(val) && /radio|checkbox/.test( this.type ) ) { - this.checked = jQuery.inArray(this.value || this.name, val) >= 0; + this.checked = jQuery.inArray( this.value, val ) >= 0; } else if ( jQuery.nodeName( this, "select" ) ) { var values = jQuery.makeArray(val); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 7521c767f..0ebae1638 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -619,7 +619,7 @@ test("clone() on XML nodes", function() { } test("val()", function() { - expect(11); + expect(15); document.getElementById('text1').value = "bla"; equals( jQuery("#text1").val(), "bla", "Check for modified value of input element" ); @@ -646,6 +646,22 @@ test("val()", function() { jQuery('#select3').val(""); same( jQuery('#select3').val(), [''], 'Call val() on a multiple="multiple" select' ); + var checks = jQuery("<input type='checkbox' name='test' value='1'/>").appendTo("#form") + .add( jQuery("<input type='checkbox' name='test' value='2'/>").appendTo("#form") ) + .add( jQuery("<input type='checkbox' name='test' value=''/>").appendTo("#form") ); + + same( checks.serialize(), "", "Get unchecked values." ); + + checks.val([ "2" ]); + same( checks.serialize(), "test=2", "Get a single checked value." ); + + checks.val([ "1", "" ]); + same( checks.serialize(), "test=1&test=", "Get multiple checked values." ); + + checks.val([ "", "2" ]); + same( checks.serialize(), "test=2&test=", "Get multiple checked values." ); + + checks.remove(); }); var testVal = function(valueObj) { |