Skip to content
Permalink
Browse files

Update :file to now be standard [type=file] selector.

  • Loading branch information
javierjulio committed Nov 19, 2012
1 parent aff16f4 commit 588306aedba1de01388032d5f42a60159eea9228
Showing with 1 addition and 1 deletion.
  1. +1 −1 jquery.form.js
@@ -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);

11 comments on commit 588306a

@thepasto

This comment has been minimized.

Copy link

@thepasto thepasto replied Nov 20, 2012

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

This comment has been minimized.

Copy link

@Gemorroj Gemorroj replied Nov 20, 2012

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

this works

@malsup

This comment has been minimized.

Copy link
Collaborator

@malsup malsup replied Nov 20, 2012

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

@rambo-panda

This comment has been minimized.

Copy link

@rambo-panda rambo-panda replied Apr 28, 2013

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

// or

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

@javierjulio

This comment has been minimized.

Copy link
Contributor Author

@javierjulio javierjulio replied Apr 28, 2013

@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

This comment has been minimized.

Copy link

@drypot drypot replied May 18, 2013

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

@drypot

This comment has been minimized.

Copy link

@drypot drypot replied May 18, 2013

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

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

This comment has been minimized.

Copy link

@Gemorroj Gemorroj replied Jun 25, 2013

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

@fleebzz

This comment has been minimized.

Copy link

@fleebzz fleebzz replied Jul 26, 2013

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

@malsup

This comment has been minimized.

Copy link
Collaborator

@malsup malsup replied Jul 31, 2013

Current impl:

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

@rahulbinod

This comment has been minimized.

Copy link

@rahulbinod rahulbinod replied Aug 24, 2013

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.
You can’t perform that action at this time.