Skip to content

Commit

Permalink
Attributes: return empty array for select-multiple with no values
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Nov 4, 2015
1 parent 493b0fd commit a179502
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/attributes/val.js
Expand Up @@ -90,7 +90,7 @@ jQuery.extend( {
var value, option,
options = elem.options,
index = elem.selectedIndex,
one = elem.type === "select-one" || index < 0,
one = elem.type === "select-one",
values = one ? null : [],
max = one ? index + 1 : options.length,
i = index < 0 ?
Expand Down
4 changes: 2 additions & 2 deletions test/unit/attributes.js
Expand Up @@ -903,10 +903,10 @@ QUnit.test( "val() with non-matching values on dropdown list", function( assert

var select6 = jQuery( "<select multiple id=\"select6\"><option value=\"1\">A</option><option value=\"2\">B</option></select>" ).appendTo( "#form" );
jQuery( select6 ).val( "nothing" );
assert.equal( jQuery( select6 ).val(), null, "Non-matching set (single value) on select-multiple" );
assert.deepEqual( jQuery( select6 ).val(), [], "Non-matching set (single value) on select-multiple" );

jQuery( select6 ).val( [ "nothing1", "nothing2" ] );
assert.equal( jQuery( select6 ).val(), null, "Non-matching set (array of values) on select-multiple" );
assert.deepEqual( jQuery( select6 ).val(), [], "Non-matching set (array of values) on select-multiple" );

select6.remove();
} );
Expand Down

0 comments on commit a179502

Please sign in to comment.