Basic frontend uploader component
This commit is contained in:
@@ -1,24 +1,37 @@
|
||||
{% from "components/icon.html" import Icon %}
|
||||
|
||||
{% macro UploadInput(field, show_label=False) -%}
|
||||
<uploadinput inline-template v-bind:initial-data='{{ field.data | tojson }}' v-bind:upload-errors='{{ field.errors | list }}'>
|
||||
<div>
|
||||
<template v-if="showUpload">
|
||||
<div class="usa-input {% if field.errors %} usa-input--error {% endif %}">
|
||||
{% if show_label %}
|
||||
{{ field.label }}
|
||||
{% endif %}
|
||||
{{ field.description }}
|
||||
{{ field }}
|
||||
{% for error in field.errors %}
|
||||
<span class="usa-input__message">{{error}}</span>
|
||||
{% endfor %}
|
||||
<div v-show="hasAttachment" class="uploaded-file">
|
||||
{{ Icon("check-circle-solid") }}
|
||||
<span class="uploaded-file__name" v-html="baseName"></span>
|
||||
<a href="#" class="uploaded-file__remove" v-on:click="removeAttachment">Remove</a>
|
||||
</div>
|
||||
<div v-show="hasAttachment === false" class="usa-input {% if field.errors %} usa-input--error {% endif %}">
|
||||
{% if show_label %}
|
||||
{{ field.label }}
|
||||
{% endif %}
|
||||
{{ field.description }}
|
||||
<div class="upload-widget">
|
||||
<label class="upload-label" for="{{ field.name }}">
|
||||
<span class="upload-button">
|
||||
Browse
|
||||
</span>
|
||||
</label>
|
||||
<input
|
||||
v-on:change="addAttachment"
|
||||
ref="attachmentInput"
|
||||
accept="{{ field.accept }}"
|
||||
id="{{ field.name }}"
|
||||
name="{{ field.name }}"
|
||||
aria-label="Task Order Upload"
|
||||
type="file">
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<p>Uploaded {{ field.data.filename }}</p>
|
||||
<div>
|
||||
<button type="button" v-on:click="showUploadInput">Change</button>
|
||||
</div>
|
||||
</template>
|
||||
{% for error in field.errors %}
|
||||
<span class="usa-input__message">{{error}}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</uploadinput>
|
||||
{%- endmacro %}
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
{% from 'components/save_button.html' import SaveButton %}
|
||||
{% from 'components/text_input.html' import TextInput %}
|
||||
{% from 'components/upload_input.html' import UploadInput %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col task-order-form">
|
||||
@@ -11,7 +12,7 @@
|
||||
{% include "portfolios/header.html" %}
|
||||
{% endblock %}
|
||||
<base-form inline-template>
|
||||
<form id="new-task-order" action='{{ url_for("task_orders.update", portfolio_id=portfolio.id) }}' method="POST" autocomplete="off">
|
||||
<form id="new-task-order" action='{{ url_for("task_orders.update", portfolio_id=portfolio.id) }}' method="POST" autocomplete="off" enctype="multipart/form-data">
|
||||
{{ form.csrf_token }}
|
||||
<div class="panel__content">
|
||||
<!-- TODO: implement save bar with component -->
|
||||
@@ -28,6 +29,7 @@
|
||||
{{ "task_orders.new.form_help_text" | translate }}
|
||||
<hr>
|
||||
{{ TextInput(form.number, validation='taskOrderNumber') }}
|
||||
{{ UploadInput(form.pdf) }}
|
||||
</div>
|
||||
</form>
|
||||
</base-form>
|
||||
|
Reference in New Issue
Block a user