dropzone icon indicating copy to clipboard operation
dropzone copied to clipboard

Adding a field to each file upload - Only able to retrieve value of first field.

Open keiffer6 opened this issue 11 years ago • 1 comments

I really don't understand how to have a separate input for each image upload. I have tried everything I can find / think of. I am using the boostrap example from the Dropzone.js website (http://www.dropzonejs.com/bootstrap.html). Here is the HTML

<div id="actions" class="row">

    <div class="col-lg-7">
        <!-- The fileinput-button span is used to style the file input field as button -->
        <span class="btn btn-success fileinput-button">
            <i class="glyphicon glyphicon-plus"></i>
            <span>Add files...</span>
        </span>
        <button type="submit" class="btn btn-primary start">
            <i class="glyphicon glyphicon-upload"></i>
            <span>Start upload</span>
        </button>
        <button type="reset" class="btn btn-warning cancel">
            <i class="glyphicon glyphicon-ban-circle"></i>
            <span>Cancel upload</span>
        </button>
    </div>

    <div class="col-lg-5">
        <!-- The global file processing state -->
        <span class="fileupload-process">
            <div id="total-progress" class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                <div class="progress-bar progress-bar-success" style="width: 0%;" data-dz-uploadprogress></div>
            </div>
        </span>
    </div>

</div>


<div class="table table-striped" class="files" id="previews">

    <div id="template" class="file-row">
        <!-- This is used as the file preview template -->
        <div>
            <span class="preview">
                <img data-dz-thumbnail /></span>
        </div>
        <div>
            <p class="name" data-dz-name></p>
            <strong class="error text-danger" data-dz-errormessage></strong>
        </div>
        <div>
            <p class="tags" data-dz-tags></p>
            <input type="text" id="tags" name="tags" />
        </div>
        <div>
            <p class="size" data-dz-size></p>
            <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                <div class="progress-bar progress-bar-success" style="width: 0%;" data-dz-uploadprogress></div>
            </div>
        </div>
        <div>
            <button class="btn btn-primary start">
                <i class="glyphicon glyphicon-upload"></i>
                <span>Start</span>
            </button>
            <button data-dz-remove class="btn btn-warning cancel">
                <i class="glyphicon glyphicon-ban-circle"></i>
                <span>Cancel</span>
            </button>
            <button data-dz-remove class="btn btn-danger delete">
                <i class="glyphicon glyphicon-trash"></i>
                <span>Delete</span>
            </button>
        </div>
    </div>

</div>

When I open the page, the input box displays exactly as I would expect for each image upload row. I have also added the following to the javascript.

myDropzone.on("sending", function (file, xhr, formData) {
     formData.append("tags", document.getElementById('tags').value);
     // Show the total progress bar when upload starts
     document.querySelector("#total-progress").style.opacity = "1";
     // And disable the start button
     file.previewElement.querySelector(".start").setAttribute("disabled", "disabled");
});

But no matter what I try, when I click the "Start Upload" button, all I can ever get back from the document.getElementById("tags").value is the value of the first input box. No matter how many files are being uploaded, each time it hits the "sending" function, it gives me the value from that first input box.

What am I missing?? This seems like a common question but I have yet to see an actual answer for it.

Thanks, Keith

keiffer6 avatar Apr 13 '15 23:04 keiffer6

Just encountered this problem today while working with multiple dropzones on a page. Haven't found a resolution yet.

pgbrown avatar May 20 '15 09:05 pgbrown