Download & Extend

Add another item causes upload, disableFields()?

Project:FileField
Version:6.x-3.x-dev
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

I'm requesting help changing the disableFields function (?) in filefield.js in hopes to let "Add another item" work without uploading any of the fields that the user has populated with a filenames but not yet uploaded.

If I change line #91 as below then the fields are cleared so no uploads occur. I'm trying to figure out what elements are included in $enabledFields. I don't understand what's going on in this module and why (guessing by the code $(this).parent().parent().) input.form-file is specified instead of input.form-submit (the Add another item button). It would seem that everything matching input.form-submit in div#field-datafiles-items is included in $enabledFields.
Is it possible to exclude these .filefield-upload elements and leave the entered filenames untouched?
Has anyone played with this? Any other suggestions on this topic?

Drupal.filefield = {
  disableFields: function(event){
      ...
      //$enabledFields = $(this).parent().parent().find('input.form-file');
      $enabledFields = $(this).parents('div.content-add-more').find('input.form-submit');

PS, I understand the need for this code from issue: #370015: Upload issue with clicking 'Add another item' multiple times (Repost w/ screencast). And the reason I'm eager to change the existing behavior is because my user's files are upwards to 1GB plus, and I really want to have progress bars in all cases. As you know, Add another causes files to get uploaded without progress bars. For the "Save" button I could resort to just throwing up an alert asking the user to upload before saving, but the same 'return false;' doesn't work for the Add-another-item button.

Comments

#1

Alternately, I'd like to just disable Save and Add another item if any of the exiting input.form-file fields are non empty. I'm trying to do this in my theme's script.js file, but struggling...

#2

I'm trying to put this into theme/script.js, but although it does what I want it to (disables Save and Add another item until files in populated fields are uploaded, because those buttons initiate all uploads without progress bars, and my users' files are many GB and must show the progress bars), except that I see the following side effect under limited circumstances.

After I "Add another item", on upload fields that were shown before adding, the progress bar doesn't work. The bar shows up but sits at 'Starting upload...' throughout the whole upload.

For example, I show two upload fields by default. If I Browse to a file on the first field, upload it, then Add another item (now there are three fields), then Browse to file-2, uploading file-2 will not show advancing progress on the bar. Then browse to file-3 and that upload works fine. Then add two more, browse to the first and that upload shows no progress. Etc.

In all cases the uploads work and the progress bar displays, it's just that the progress % doesn't creep up. I see this behavior in both Firefox 3.x and IE7.

Except for this small glitch it works fine. But if anyone has an idea why this would happen then please chime in. Thanks!

//toggle Save+Add OFF
Drupal.behaviors.waitSave = function (context) {
  $('.form-file', context).each(function () {
    $(this).change(function() {
      if($(this).val() != '') {
        $('#edit-field-datafiles-field-datafiles-add-more').attr('disabled','disabled').fadeTo(200,.20);
        $('#edit-submit').attr('disabled','disabled').fadeTo(200,.20);
      }
    });
  });
}

//toggle Save+Add ON
Drupal.behaviors.readySave = function (context) {
   var queued = 0;
   $('#field-datafiles-items').find('.form-file').each(function(){
      if ( jQuery(this).val() !='' ) {
         queued++;
      }
   });
   if (queued === 0) {
      $('#edit-field-datafiles-field-datafiles-add-more').removeAttr('disabled').fadeTo(200,1);
      $('#edit-submit').removeAttr('disabled').fadeTo(200,1);
   }
}

#3

Status:active» closed (fixed)

I verified this "Add another item" problem with a clean install of Drupal 6.13, CCK 6.x-2.5, and Filefield 6.x-3.x-dev. So I 've submitted a bug report #547216: Add another item breaks progress bar.

Closing this request -- this script.js code works for me and seems a nice way to address this issue for now.