Hi, Is it possible to allow users to upload a fixed number of files(3) but only upload one file at a time, so only allow them upload the second file when the first file has been successfully been uploaded.

Comments

nagarajanl’s picture

You can specify the maximu value as 3 for the filefield and add a custom validator for the corresponding form which will trigger an error of we are trying to upload a second file in which the first file has not updated properly.

Check this url for more info http://drupal.org/node/546146

droid19’s picture

Thanks for the sharp response, However I would like to disable the other fields until the previous file has uploaded via JS.

Is it possible to know which part of the filefield.js is triggering the GET request or gets invoked on uploaded completion so I can disable/enable the 2 other fields.

nagarajanl’s picture

When you upload a filefield(lets say an image or a doc), automatically the preview wrapper with

etc will be displayed above the filefield with the preview image. This will make sure that the file has uploaded properly.

So in your custom javascript just check whether the preview wrapper has displayed there for the first file field, if its there then enable the other 2 fields based on the same logic..

droid19’s picture

nice, didn't think of that. This means I have to poll, is it possible without polling?

nagarajanl’s picture

Yeah..it is possible without polling...just look into the poll.module and see how the AHAH mechanism is implemented there..You can also do the same thing here...

droid19’s picture

Thanks nagarajanl. The below has done the trick for me. Anyone interested, just stick this in a js file and add it to the page using drupal_add_js in your form_alter implementation.

/**
* Only allow users to upload one file at a time
**/
var upload_counter 	= 1;
var field_name     	= 'field_entry_attachment_file';
var field_id		= '#' + field_name + '_values';
$(function(){
	$(field_id + ' tbody tr').not(':first').each(function(){
		$(this).toggle();
	});
	
	var timer = setInterval(function(){
		var tr = $(field_id + ' tbody tr:nth-child(' + upload_counter + ')');
		if($('.widget-preview', tr).size()) {
			upload_counter++;
			tr = $(field_id + ' tbody tr:nth-child(' + upload_counter + ')');
			if($(tr).size()) {
				$(tr).toggle();
			}
			else {
				clearTimeout(timer);
			}
		}	
	}, 1000);
});
quicksketch’s picture

Status: Active » Fixed

Sweet, thanks for the help nagarajanl.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.