Skip to content

Commit

Permalink
$.fn.val: ensuring it works with “input[type=file][multiple]” elements
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiospampinato committed Sep 6, 2019
1 parent a0d8cbc commit 406bd3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/forms/helpers/get_value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

function getValue ( ele: Ele ): string | string[] {

if ( ele.multiple ) return pluck ( filter.call ( ele.options, option => option.selected && !option.disabled && !option.parentNode.disabled ), 'value' );
if ( ele.multiple && ele.options ) return pluck ( filter.call ( ele.options, option => option.selected && !option.disabled && !option.parentNode.disabled ), 'value' );

return ele.value || '';

Expand Down
9 changes: 9 additions & 0 deletions test/modules/forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var fixture = '\
<option value="option-2" selected>Selected</option>\
</select>\
<input type="file" name="file" />\
<input type="file" name="file-multiple" multiple />\
<input type="submit" value="submit" name="submit" />\
</form>\
';
Expand Down Expand Up @@ -61,6 +62,14 @@ describe ( 'Forms', { beforeEach: getFixtureInit ( fixture ) }, function () {

});

it ( 'gets the value of input file multiple', function ( t ) {

var val = $('.form input[type=file][multiple]').val ();

t.is ( val, '' );

});

it ( 'gets the value of select', function ( t ) {

var val = $('select[name=select]').val ();
Expand Down

0 comments on commit 406bd3d

Please sign in to comment.