grevory / bootstrap-file-input

Standardizes the file input field to look like a Bootstrap button in all browsers
Other
179 stars 63 forks source link

File name is not shown in IE 9 due to javascript failure #14

Closed thoraage closed 11 years ago

thoraage commented 11 years ago

I get the message:

SCRIPT5007: Unable to get value of the property 'length': object is null or undefined bootstrap-file-input.js, line 84 character 5

Otherwise it seems to work well; the file is uploaded and everything.

grevory commented 11 years ago

Thanks for the heads up. I only tested this in IE8 since I made a major change so I kind of assumed it would work in later versions (though I know that's never the case).

I will check this ASAP.

grevory commented 11 years ago

What version of jQuery are you running? This will only work for version 1.6 and higher. Thanks.

thoraage commented 11 years ago

I use jquery v1.8.3. It works fine with firefox and chrome. It's only IE 9 (9.0.8112.16421) that's acting out.

On Mon, May 6, 2013 at 8:37 AM, grevory notifications@github.com wrote:

What version of jQuery are you running? This will only work for version 1.6 and higher. Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/grevory/bootstrap-file-input/issues/14#issuecomment-17468095 .

grevory commented 11 years ago

Thanks! I wanted to make sure there were truly an IE9 bug before I install a VM to test.

tsukisu412 commented 11 years ago

How about following code? It works fine on Chrome, FF, IE8-10,Lunascape(Webkit) and Chrome on Ubuntu 13.04.

$('.file-input-wrapper input[type=file]').change(function(){ var fileName; $(this).parent().next('.file-input-name').remove(); if ($(this).prop('files') && $(this).prop('files').length > 1) { $(this).parent().after(''+$(this)[0].files.length+' files'); } else { fileName = $(this).val(); if(fileName.indexOf('C:\fakepath\') > -1){ fileName = fileName.replace('C:\fakepath\',''); }else{ fileName = fileName.substring(fileName.lastIndexOf('\')+1,fileName.length); } $(this).parent().after(''+fileName+''); } });

thoraage commented 11 years ago

Hi

There seems to be a problem with this (in IE, Chrome and possibly others).

The string literals with \ needs to be escaped with . Also when I try to upload again it will prepend the new name to the old one

On Wed, May 8, 2013 at 2:51 AM, tsukisu412 notifications@github.com wrote:

How about following code? It works fine on Chrome, FF, IE8-10,Lunascape(Webkit) and Chrome on Ubuntu 13.04.

$('.file-input-wrapper input[type=file]').change(function(){ var fileName; $(this).parent().next('.file-input-name').remove(); if ($(this).prop('files') && $(this).prop('files').length > 1) { $(this).parent().after(''+$(this)[0].files.length+' files'); } else { fileName = $(this).val(); if(fileName.indexOf('C:\fakepath\') > -1){ fileName = fileName.replace('C:\fakepath\',''); }else{ fileName = fileName.substring(fileName.lastIndexOf('\')+1,fileName.length); } $(this).parent().after(''+fileName+''); } });

— Reply to this email directly or view it on GitHubhttps://github.com/grevory/bootstrap-file-input/issues/14#issuecomment-17580345 .

grevory commented 11 years ago

I haven't had the chance to install a VM with IE9. Any chance you can test this fix? https://github.com/grevory/bootstrap-file-input/tree/523fb644b84fc52a28a46937158b7259cd439608

adesalvo commented 11 years ago

I can verify the above fix is working in IE9

grevory commented 11 years ago

Thank you!