{% load bootstrap %}
{% load crispy_forms_filters %}
{% load i18n %}
{% load formset_tags %}

{{ form|crispy }}


<div class="formset" data-formset data-formset-prefix="{{ form.sections_formset.prefix }}">
    {{ form.sections_formset.management_form }}
    <div class="card mb-2">
        <div class="card-body">
            <h3 class="card-title">{% translate "Sections" %}</h3>
            {{ form.sections_formset|formset_errors }}
            <ul class="list-group list-group-flush" data-formset-body>
                {% for section_form in form.sections_formset %}
                    <div class="list-group-item" data-formset-form>
                        <div class="row align-items-center">
                            <div class="col-md-3">
                                {{ section_form.title|as_crispy_field }}
                            </div>
                            <div class="col-md-2">
                                {{ section_form.min_count|as_crispy_field }}
                            </div>
                            <div class="col-md-2">
                                {{ section_form.max_count|as_crispy_field }}
                            </div>
                            <div class="col-md-4">
                                {{ section_form.qualifications|as_crispy_field }}
                            </div>
                            <div class="col-md-1">
                                <button class="btn btn-link" type="button"
                                        data-formset-delete-button><span
                                        class="fas fa-trash-alt"></span></button>
                            </div>
                        </div>
                        <div class="d-none">
                            {{ section_form.DELETE }}
                            {{ section_form.uuid }}
                        </div>
                    </div>
                {% endfor %}
            </ul>

            <input class="btn btn-secondary mt-2" type="button"
                   value="{% translate "Add section" %}"
                   data-formset-add>
        </div>
    </div>

    <script type="form-template" data-formset-empty-form>
        {% escapescript %}
            <div class="list-group-item" data-formset-form>
                <div class="row align-items-center">
                    <div class="col-md-3">
                        {{ form.sections_formset.empty_form.title|as_crispy_field }}
                    </div>
                    <div class="col-md-2">
                        {{ form.sections_formset.empty_form.min_count|as_crispy_field }}
                    </div>
                    <div class="col-md-2">
                        {{ form.sections_formset.empty_form.max_count|as_crispy_field }}
                    </div>
                    <div class="col-md-4">
                        {{ form.sections_formset.empty_form.qualifications|as_crispy_field }}
                    </div>
                    <div class="col-md-1">
                        <button class="btn btn-link" type="button"
                                data-formset-delete-button><span
                                class="fas fa-trash-alt"></span></button>
                    </div>
                </div>
            </div>
            <div class="d-none">
                {{ form.sections_formset.empty_form.DELETE }}
                {{ form.sections_formset.empty_form.uuid }}
            </div>
        {% endescapescript %}
    </script>
</div>