Skip to content

Add other filed alongside the upload #2

@kasravnd

Description

@kasravnd

If someone wants to add another field like a ChoiceField and/or CharField since the upload button immediately triggers a POST request there's no chance to send other field within the request and therefore form never gets validated. Is it possible to after uploading the files use another submit button for submitting the form include uploaded files at once? some thing like the following snippet?

<form action="/" method="POST">{% csrf_token %}
  <div class="custom-select" style="width:200px;">
      <li>{{ form.interface.label_tag }} {{ form.interface }}</li>
  </div>
<div class="custom-select" style="width:200px;">
      <li>{{ form.environment.label_tag }} {{ form.environment }}</li>
</div>
<br>
  <div style="margin-bottom: 20px;">
    <button type="button" class="btn btn-primary js-upload-photos">
      <span class="glyphicon glyphicon-cloud-upload"></span> Upload files
    </button>
    <input id="fileupload" type="file" name="file" multiple
    style="display: none;"
    data-url="{% url 'home' %}"
    data-form-data='{"csrfmiddlewaretoken": "{{ csrf_token }}"}'>
<br>
</div>
<div style="margin-bottom: 20px;">
    <button type="submit" class="btn btn-success">
        <span class="glyphicon glyphicon glyphicon-ok"></span> Submit
      </button>
    </div>  
    </form>  

In this case, If I hit the submit it raise the field required error for file field and if I hit the upload it raises the error for other fields.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions