Skip to content

Commit 79fc806

Browse files
committed
Attributes: return empty array for select-multiple with no values
Fixes gh-2562 Close gh-2689
1 parent e05c63e commit 79fc806

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/attributes/val.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jQuery.extend( {
9090
var value, option,
9191
options = elem.options,
9292
index = elem.selectedIndex,
93-
one = elem.type === "select-one" || index < 0,
93+
one = elem.type === "select-one",
9494
values = one ? null : [],
9595
max = one ? index + 1 : options.length,
9696
i = index < 0 ?

test/unit/attributes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@ QUnit.test( "val() with non-matching values on dropdown list", function( assert
903903

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

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

911911
select6.remove();
912912
} );

0 commit comments

Comments
 (0)