2023-08-30 11:07:38 -04:00
{% from "components/components/button/macro.njk" import usaButton %}
2020-02-06 13:35:08 +00:00
2018-03-29 11:56:53 +01:00
{% macro file_upload(
field,
2020-12-16 10:13:49 +00:00
allowed_file_extensions,
2018-03-29 11:56:53 +01:00
action=None,
button_text="Choose file",
alternate_link=None,
2018-09-26 16:42:40 +01:00
alternate_link_text=None,
2019-10-15 15:56:06 +01:00
hint=None,
show_errors=True
2018-09-26 16:42:40 +01:00
2018-03-29 11:56:53 +01:00
) %}
2019-10-15 15:56:06 +01:00
< form method = "post" enctype = "multipart/form-data" { % if action % } action = "{{ action }}" { % endif % } class = "{% if field.errors and show_errors %}form-group-error{% endif %}" data-module = "file-upload" >
2016-02-02 17:28:30 +00:00
< label class = "file-upload-label" for = "{{ field.name }}" >
2023-06-16 14:55:24 -04:00
< span class = "usa-sr-only" > {{ field.label.text }}< / span >
2016-02-02 17:28:30 +00:00
{% if hint %}
< span class = "form-hint" >
{{ hint }}
< / span >
{% endif %}
2019-10-15 15:56:06 +01:00
{% if field.errors and show_errors %}
2016-02-02 17:28:30 +00:00
< span class = "error-message" >
{{ field.errors[0] }}
< / span >
{% endif %}
< / label >
{{ field(**{
2020-12-16 10:13:49 +00:00
'class': 'file-upload-field',
2020-12-17 10:49:36 +00:00
'accept': allowed_file_extensions|format_list_items('.{item}')|join(',')|e
2016-02-02 17:28:30 +00:00
}) }}
< label class = "file-upload-button" for = "{{ field.name }}" >
2016-02-04 12:20:24 +00:00
{{ button_text }}
2016-02-02 17:28:30 +00:00
< / label >
2016-05-05 08:39:36 +01:00
{% if alternate_link and alternate_link_text %}
< span class = "file-upload-alternate-link" >
2023-08-08 16:19:17 -04:00
or < a class = "usa-link" href = "{{ alternate_link }}" > {{ alternate_link_text }}< / a >
2016-05-05 08:39:36 +01:00
< / span >
{% endif %}
2016-02-02 17:28:30 +00:00
< label class = "file-upload-filename" for = "{{ field.name }}" > < / label >
2016-02-22 21:37:32 +00:00
< input type = "hidden" name = "csrf_token" value = "{{ csrf_token() }}" / >
2023-08-30 11:07:38 -04:00
{{ usaButton({ "text": "Submit", "classes": "file-upload-submit" }) }}
2016-02-22 21:37:32 +00:00
< / form >
2016-02-02 17:28:30 +00:00
{% endmacro %}