0

I need to create a drag and drop page. I am currently using "Dropzone" plugin. In my client I have the following html:

Here I select a Value from an input:

<div class="form-group">
    <label for="selectMarca" class="col-sm-3">Selecione o tipo de Comerciantes a Importar</label>
    <select class="form-control" id="selector">
        <option value=0>Value0</option>
        <option value=1>Value1</option>
        <option value=2>Value2</option>
        <option value=3>Value3</option>
    </select>
</div>

Here is where I call the function SaveUploadedFile:

<form class="dropzone" id="dropzoneForm" action="/SettingsMerchants/SaveUploadedFile/0" data-plugin="dropzone">
    <div class="dz-message">
        <h3 class="m-h-lg">Press here or drag some file to import</h3>
     </div>
 </form>

And I have a Jquery trigger to change that "action" value:

<script>
    $("#selector").on("change", function (e) {
        //e.preventDefault();
        $('#dropzoneForm').attr('action', "/SettingsMerchants/SaveUploadedFile/" + $("#selector").val());
    });
</script>

My problem is that when I drop a file always calls my function with '0'. But when I change the value on select/option it changes, if I go to browser console and type:

$('#dropzoneForm').attr('action')

I see the value changed.

enter image description here

enter image description here

gn66
  • 803
  • 2
  • 12
  • 33
  • 1
    Change your default action attribute to something like: action="/SettingsMerchants/SaveUploadedFile/666" and see if the value that comes through on your controller is 666, or if it's still 0. If it's still 0, then I think it might have to do with the routing or parameter identifier in your controller, not the jQuery setting of the attribute. – Ben Krueger Apr 02 '19 at 18:43
  • It does assume 666. If I even take the id he complains its null. The problem is that it looks like he always look the begining attribute not the changed value. – gn66 Apr 03 '19 at 09:17

1 Answers1

0

Based off of this answer:

https://github.com/enyo/dropzone/wiki/Set-URL-dynamically

I'm assuming the Dropzone JS takes the initial value in the action attribute and stores that on the JS side, and then doesn't pull from that after it has been initialized, which is why you need to set the url property on the Dropzone object directly as shown in the above example.

Ben Krueger
  • 1,476
  • 1
  • 14
  • 20