{% load wger_extras %}
{% load i18n %}
<div id="formset-exercise-{{exercise.id}}" style="margin-top: 1em;">
<div class="row">
    <div class="col-md-offset-2 col-md-10">
        <label class="control-label">
            {{exercise}}
        </label>
    </div>
</div>
{{ formset.management_form }}

{% for field in formset %}
<div style="padding-top: 0.5em;">

    {# Header row with field labels, only for first loop #}
    <div class="row">
        {% for i in field %}
        {% if not i.is_hidden %}
            {% if forloop.first %}
            <div class="col-xs-2">
            </div>
            {% endif %}

            {% if forloop.parentloop.first %}
                <div class="{% cycle 'col-xs-3' 'col-xs-2' %}">
                    {{ i.label }}
                    {% if not i.field.required %}
                        <br>
                        <span style="font-size:90%;">— <em>{% trans "Optional" %}</em></span>
                    {% endif %}
                </div>
            {% endif %}
        {% endif %}
        {% endfor %}
    </div>

    {# Form field rows #}
    <div class="row">
        {% for i in field %}
            {% if forloop.first %}
            <div class="col-xs-2" style="text-align: right; padding-left: 0px;">
                {% trans "Nr." %} {{ forloop.parentloop.counter }}
            </div>
            {% endif %}

            {% if not i.is_hidden %}
            <div class="{% cycle 'col-xs-3' 'col-xs-2' %} {% if i.errors %}has-error{% endif %}" style="padding-left: 0px;">
            {% endif %}

            {#  Field elements #}
            {% if i|is_checkbox %}
                {{ i|form_field_add_css:'checkbox' }}
            {% else %}
                {{i|form_field_add_css:'form-control'}}
            {% endif %}

            {% for error in i.errors %}
                <div {% if i.errors %}class="has-error has-feedback"{% endif %}>
                <span class="help-block">
                    <p>{% trans error %}</p>
                </span>
                </div>
            {% endfor %}

            {% if not i.is_hidden %}
            </div>
            {% endif %}
        {% endfor %}
    </div>
</div>
{% endfor %}
</div>
