{# Because of browser limitations, we can't populate a `<input type="file">` field if we are on a #}
{# multi-page, page reload form with already uploaded assets. As such, we'll get an validation #}
{# error when going back to a previous page and submitting again, as the field will be empty #}
{# despite files being uploaded. Here, force the field to be non-required if a value exists. #}
{% set required = value and value.all() ? false : field.required %}

{# Output any existing element IDs for already-uploaded assets, which can be overidden #}
{# when uploading new files #}
{% if value %}
    {% for element in value.all() %}
        <input type="hidden" name="{{ field.getHtmlName('[]') }}" value="{{ element.id }}">
    {% endfor %}
{% endif %}

{{ fieldtag('fieldInput', {
    required: required ? true : false,
}) }}

{% if value %}
    {% set elements = value.all() %}

    {% if elements %}
        {% fieldtag 'fieldSummary' %}
            {% if elements | length == 1 %}
                <p>{{ '{num} file uploaded.' | t('formie', { num: elements | length }) }}</p>
            {% else %}
                <p>{{ '{num} files uploaded.' | t('formie', { num: elements | length }) }}</p>
            {% endif %}

            {% fieldtag 'fieldSummaryContainer' %}
                {% for element in elements %}
                    {% fieldtag 'fieldSummaryItem' %}
                        {{ element.filename }}
                    {% endfieldtag %}
                {% endfor %}
            {% endfieldtag %}
        {% endfieldtag %}
    {% endif %}
{% endif %}