Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74074

DropZone JS not grabbing external value from input field called by jQuery ID

$
0
0

I am experiencing an issue with DropZone JS Grabbing an input value and passing it along to the upload script. The upload is working and everything is fine EXCEPT this field not sending in the POST.

I have a very basic DZ config:

$("#file_uploader").dropzone({
    url: '/ajax/upload.php',
    dictDefaultMessage: 'Drop photos or click here to upload',
    maxFilesize: 400000,
    params: {'project': $('#project-name').val()}, // This is the part I am having issues with
    success: function (file, response) {
        var obj = JSON.parse(response);
        if (obj.status === 'success') {
            console.log('gtg');
        } else {
            alert('upload failed');
            $(".dz-preview").remove();
        }
    }
});

I have a field in my html that looks like:

<input type="text" id="project-name" required="required"
       class="form-control col-md-6 col-xs-12 limited_form"
       placeholder="Project Name">

If I simply overwrite 'project': $('#project-name').val() to look like:

'project': 'test'

It works. So it's a matter of Dropzone not being able to "see" that input field for some reason.

I thought it might be the dash in the id project-name -- But according to the rules in HTML5 dashes are allowed in Ids.

There are no errors in the console, and this:

// Testing if Selector is working
$(document).on('keyup', '#project-name', function () {
    console.log( $('#project-name').val() );
});

displays the project-name contents in the console correctly as I type them, so I know my selector is OK. Thus, my confusion on why DropZone isn't "seeing" it.

Why is DropZone "ignoring" my jQuery identified by selector id? Am I missing something glaringly wrong?

UPDATE It is worth noting that my config lies within a $(document).ready(function () { -- However I have tried it both inside, and outside the function and still the problem persists.


Viewing all articles
Browse latest Browse all 74074

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>