Bug #8331 Lots of extra file upload slots
Submitted: 5 Feb 2005 7:27 Modified: 7 Feb 2005 20:08
Reporter: Paul Mach Email Updates:
Status: Closed Impact on me:
None 
Category:Eventum Severity:S3 (Non-critical)
Version:1.4 OS:
Assigned to: Bryan Alsdorf CPU Architecture:Any

[5 Feb 2005 7:27] Paul Mach
Description:
When creating an issue it is possible to upload files. Currently, whenever one of the file inputs is changed another input is added.

If someone selects the wrong file and then reselect the correct one, they will have three input boxes.

I suggest that if there is already a empty file upload box at the end, another should not be added.

How to repeat:
Visit the Create New Issue Page
Select a file to upload (click browse, select file)
Change that file (click the same browse, select another file)
   There will now be three file input boxes, 1 too many

Suggested fix:
If there is a blank file input at the end, don't add another.

Here is the suggested code. It was implement on 1.4 and the javascript was tested with IE 6, Firefox 1.0 and Opera 7.54

Modify line 363 of \templates\en\new.tpl.html to look like this (just id="file1" was added)
                  <input type="file" id="file1" name="file[]" size="40" class="shortcut" onChange="javascript:addFileRow('file_table', 'file[]');">

Modify addFileRow function in /js/global.js to look like this

function addFileRow(element_name, field_name)
{
    if (document.all) {
        var fileTable = document.all[element_name];
    } else if (!document.all && document.getElementById) {
        var fileTable = document.getElementById(element_name);
    }
    if (!fileTable) {
        return;
    }
    
    rows = fileTable.rows.length;

    if (document.all) {
        var last_file_element = document.all['file' + rows];
    } else if (!document.all && document.getElementById) {
        var last_file_element = document.getElementById('file' + rows);
    }
		
    if (last_file_element.value != '')
    {
        newRow = fileTable.insertRow(rows);
        cell = newRow.insertCell(0);
    
        if (document.all) {
            cell.innerHTML = '<input id="file' + (rows+1) + '" class="shortcut" size="40" type="file" name="' + field_name + '" onChange="javascript:addFileRow(\'' + element_name + '\', \'' + field_name + '\');">';
        } else {
            var input = document.createElement('INPUT');
            input.setAttribute('type', 'file');
            input.name = field_name;
            input.className = 'shortcut';
            input.id = 'file' + (rows+1);
            input.size = 40;
            input.onchange = new Function('addFileRow(\'' + element_name + '\', \'' + field_name + '\');');
            cell.appendChild(input);
        }
    }
}
[7 Feb 2005 20:08] Bryan Alsdorf
Thanks for the report. I just pushed a fix to bitkeeper and it will be in our next release.
[8 Feb 2005 2:55] Paul Mach
I don't know if I'm missing something, but according to the log at bit keeper you did not push the js changes.

I'm going by the data on this page http://mysql.bkbits.net:8080/eventum/cset@1.392