Index: filefield.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.js,v retrieving revision 1.13 diff -u -r1.13 filefield.js --- filefield.js 31 Jan 2009 17:56:22 -0000 1.13 +++ filefield.js 2 Mar 2009 04:53:29 -0000 @@ -30,4 +30,38 @@ */ /* @todo */ }); -} +}; + +/** + * Prevent FileField uploads when using buttons not intended to upload. + */ +Drupal.behaviors.filefieldButtons = function(context) { + $('input.form-submit.ahah-processed').bind('mousedown', Drupal.filefield.disableFields); +}; + +/** + * Utility functions for use by FileField. + * @param {Object} event + */ +Drupal.filefield = { + disableFields: function(event){ + var clickedButton = this; + + // Using the grandparent, we ensure that we get up to at least the level + // of the CCK multiple field wrapper. + var $enabledFields = $(this).parent().parent().find('input.form-file'); + var $disabledFields = $('div.filefield-element input.form-file').not($enabledFields); + + // Disable upload fields other than the one we're currently working with. + $disabledFields.attr('disabled', 'disabled'); + + // All the other mousedown handlers (like AHAH) are excuted before any + // timeout functions will be called, so this effectively re-enables + // the filefields after the AHAH process is complete even though it only + // has a 1 millisecond timeout. + setTimeout(function(){ + $disabledFields.attr('disabled', ''); + }, 1); + } +}; +