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);
}
}
}