Skip to content

Commit

Permalink
Update :file to now be standard [type=file] selector.
Browse files Browse the repository at this point in the history
  • Loading branch information
javierjulio committed Nov 19, 2012
1 parent aff16f4 commit 588306a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion jquery.form.js
Expand Up @@ -172,7 +172,7 @@ $.fn.ajaxSubmit = function(options) {
};

// are there files to upload?
var fileInputs = $('input:file:enabled[value]', this); // [value] (issue #113)
var fileInputs = $('input[type=file]:enabled[value]', this); // [value] (issue #113)
var hasFileInputs = fileInputs.length > 0;
var mp = 'multipart/form-data';
var multipart = ($form.attr('enctype') == mp || $form.attr('encoding') == mp);
Expand Down

11 comments on commit 588306a

@thepasto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file input type seems to be not recognized in this way:

I.E:
"input type="file" name="file_binario" id="file_binario"

$('input:file:enabled[value]') returns
["input type=​"file" name=​"file_binario" id=​"file_binario​"]

instead

$('input[type=file]:enabled[value]') returns
[]

Any suggestion? Tnx

@Gemorroj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$('input[type=file]:enabled')

this works

@malsup
Copy link
Collaborator

@malsup malsup commented on 588306a Nov 20, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to $('input[type=file]:enabled[value!=""]', this);

@rambo-panda
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$('input[type="file"]:enabled[value!==""]',this); //Will be better

// or

$('input:file:enabled[value!==""]',this); // l like

@javierjulio
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rambo-panda just to make sure you are aware that the :file selector has been deprecated. Newer versions of jQuery will only support the standard selector e.g. input[type="file"]

@drypot
Copy link

@drypot drypot commented on 588306a May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like $('#new-form input[type=file]:enabled[value!=""]').length returns 0 on IE even if file is selected.

@drypot
Copy link

@drypot drypot commented on 588306a May 18, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[value!=""] does not work on IE. How about this ?

var fileInputs = $('input[type=file]:enabled', this).filter(function () {
    return $(this).val()
});

@Gemorroj
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem occurs only in IE if you do not specify enctype. (enctype="multipart/form-data")

@fleebzz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Gemorroj @drypot In Chrome [value!=""] does not work when enctype="multipart/form-data" is not specified

@malsup
Copy link
Collaborator

@malsup malsup commented on 588306a Jul 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current impl:

var fileInputs = $('input[type=file]:enabled:not([value=""])', this);

@rahulbinod
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: Progress Bar was getting filled to 100% without selecting any file.

/* i have added this patch to resolve the issue */
if($('#myfile').val() == ''){
$('#message').css('color','red');
$('#message').html('Please select a file first & then click on Upload');
return false;
}
It's working for me..

Does anybody have any idea

Please sign in to comment.