still wondering why its so easy to break the node creation when hitting save/submit on nodecreation before filefield uploadstatus reaches 100% cant find any info about this? noone run into this?
am i stupid to believe people will start a file upload and hit save before it is completly uploaded ? can find no obvious/simple way to prevent this?!

it works if i wait for upload field to finish upload before submitting, and also when hitting submit without hitting upload (yet that doesnt show status) Iḿ just wondering if there is a way i can prevent users to hit save before upload is complete

someone must have thought about this: big file in filefield on nodecreation beautiful click upload watch statusbar, click submit before upload complete and node is broken... ?! wtf? there must be a way to prevent

I might be underestimating my users.

it would be great if, in case the user chooses a file and hits save without upload first, the upload would either run in background or show the status.
its also great that i can fill out other fields while the ajaxupload runs and shows progressbar but if i am done filling out extra fields I automatically hit save which causes the nodecreation to break couldnt the save button be hidden during upload?

am i missing something obvious here?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mudd’s picture

I get this too. In this post I outlined what I did to get around it: #542038: Add another item causes upload, disableFields()? (I only closed this because it's going to take some effort with CCK dev's and 7.0 will be out before much happens with this (??)
Note too that Add-another-item breaks the progress bar for all but the last added field. Tho you can create a node and upload from the default empty field, then add-another and upload, then add-another and upload, etc.. and progress bars work, if you add-another before you upload the original empty field, or add several fields before populating and uploading them, then things start to break. More on that issue here: #491228: Progress bar does not make progress.

rooby’s picture

Thanks mudd for that code

Here is a .js file with mudd's code in it (it also disables the preview button).
Just add this file to your theme (remove the _.txt part from the file name) and add the following line to your themes info file:

scripts[] = upload_disabled_buttons.js
rooby’s picture

Be careful with that javascript though. Because it looks for any file fields you will run
into problems when you have file fields that don't have an upload button (like on image nodes).

In this case your save buttons will never enable again.

You should modify the js to suit your needs in these cases.

quicksketch’s picture

Title: disable submit/save node during ajax-upload » Disable submit/save node during ajax-upload

I'd be happy to include these changes directly in FileField if a patch can be provided. This is one of the things that was on the wish-list but just was never implemented.

rooby’s picture

Status: Active » Needs review
FileSize
1.4 KB

Here is a quick patch for this.

It's based on #2 with a couple of changes.

It doesn't suffer from the problem mentioned in #3.

It currently disables the save/submit, preview, delete & add another item buttons.

Feel free to change which buttons are disabled to suit the requirements.

[EDIT] It's against 6.x-3.x-dev

pumpkinkid’s picture

Has this been included in any version of filefield yet?

quicksketch’s picture

Status: Needs review » Needs work

No, if it had been, it would be marked "fixed". You can help by applying the patch and reviewing its behavior. Generally it looks pretty good, though there are some semantic problems, we shouldn't be using names like "waitSave", it should be namespaced into "filefieldWaitSave". I'm also not sure about the approach, it looks like this would disable the save and preview buttons just by selecting a file, not uploading one. Additionally a name like $('#edit-field-file-field-file-add-more') is hard-coded, meaning this will only work if you name your field "field_file".

pumpkinkid’s picture

I will look into it and let you know what I find. Thanks for your response!

hatsch’s picture

this works far better then the current default behavior.

i don't have multiple files so i could only test the upload button.

it's true that the save/preview buttons are disabled as soon as a file is selected. would be better if pressing the upload button would be used as a trigger.

rooby’s picture

Status: Needs work » Needs review
FileSize
1.06 KB

I just had a quick look at this again.
What about something like this.
It is extremely generic compared to the previous one.
It disables all input elements of type submit and it works based on clicking the upload button.

braindrift’s picture

Hi,

for me this patch looks great.

Additional it would also be great, if all the buttons would be disabled as soon as a file is selected, so the user is forced to push the upload button before he can hit the save button.

Is it possible?

Thanks
dendie

rooby’s picture

@dendie:

The functionality of disabling on the click of the upload button was what was recommended by the module quicksketch (the filefield maintainer) in #7.

Off the top of my head I'm pretty sure that clicking submit before you have clicked upload doesn't cause any problems.
Clicking submit during upload does cause problems, which is what this patch aims to resolve.
So that functionality might not be something the module will provide out of the box, but you could add it to your site specifically is you wanted.

But ultimately it's up to quicksketch if it is to get in this patch.

quicksketch’s picture

Status: Needs review » Needs work

I'm not sure disabling all buttons is a good approach either. Some users like to make 6 file upload fields and then upload them all at once. Uploading a file also shouldn't do things like prevent you from using the Teaser Splitter or adding more fields to other CCK fields.

In any case it looks like the current patch doesn't ever re-enable the buttons at all, so I'm moving back to needs work.

carvalhar’s picture

well, i think #10 is a nice add-on.
If users will or won't like this feature, is something that should be added as a configuration option.

I also used the code from here:
http://drupal.org/node/540138

JordanMagnuson’s picture

Anyone know how to accomplish something like this in Drupal 7 with build-in file field?

iiioufmaniii’s picture

Issue summary: View changes

Hey,

On drupal 7 I use a hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) where I put
$form['#attached']['js']['PATH-TO-JS/disablesubmit.js'] = array('type'=> 'file', 'weight'=>'1');

to attache disablesubmit.js code.

And disablesubmit.js is :

// This script disable the save, preview and delete button while the ajax is executed.
(function ($, Drupal, window, document, undefined) {
  'use strict';

  // Disable buttons during ajax.
  Drupal.behaviors.duringajax = {
    attach: function (context) {
      $('#YOUR-FORM-ID', context).ajaxStart(function () {
        $('#edit-submit').attr('disabled', 'disabled');
        $('#edit-preview').attr('disabled', 'disabled');
        $('#edit-delete').attr('disabled', 'disabled');
      });
    }
  };

  // Enable buttons at the end of ajax.
  Drupal.behaviors.afterajax = {
    attach: function (context) {
      $('#YOUR-FORM-ID', context).ajaxComplete(function () {
        $('#edit-submit').removeAttr('disabled');
        $('#edit-preview').removeAttr('disabled');
        $('#edit-delete').removeAttr('disabled');
      });
    }
  };

})(jQuery, Drupal, window, this.document);