Index: filefield.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.js,v retrieving revision 1.1.2.3 diff -u -p -r1.1.2.3 filefield.js --- filefield.js 1 Aug 2008 18:09:40 -0000 1.1.2.3 +++ filefield.js 3 Dec 2008 21:34:13 -0000 @@ -4,30 +4,30 @@ * Auto Attach standard client side file input validation */ Drupal.filefieldValidateAutoAttach = function() { - $("input[@type='file']").change( function() { - $('.filefield-js-error').remove(); + $("input[@type='file'][accept]", context).change( function() { + // Remove any previous errors. + $('.file-upload-js-error').remove(); + /** - * add client side validation for the input[@file] accept attribute + * Add client side validation for the input[@file] accept attribute. */ - - if(this.accept.length>1){ - accept = this.accept.replace(',', '|'); - v = new RegExp('\\.('+(accept?accept:'')+')$','gi'); + if (this.accept.length > 1) { + var v = new RegExp('\\.(' + this.accept.replace(/,\s*/g, '|') + ')$', 'gi'); if (!v.test(this.value)) { - var error = 'The file ' + this.value + " is not supported.\n"; - error += "Only the following file types are supported: \n" + accept.replace(/\|/g, ', '); - alert(error); - // what do I prepend this to? - // .prepend($('
')); - this.value = ''; + var error = 'The selected file ' + this.value + ' cannot not be uploaded. Only files with the following extensions are allowed: ' + accept.replace(/\|/g, ', '); + + // What do I prepend this to? + $(this).before('
' + error + '
'); + this.value = ''; return false; - } - } + } + } + /** - * Add filesize validation where possible + * Add filesize validation where possible. */ - - }); + /* @todo */ + }); } // Global killswitch