{% load addcss %}
{% load form_utils %}
{{ child.media }}

<!--{% if child.errors %}-->
<!--<p class="alert alert-danger alert-dismissable">-->
    <!--<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>-->
    <!--Please correct the error{{ child.errors|pluralize }} below.-->
<!--</p>-->
<!--{% endif %}-->

<!--{% if child.non_field_errors %}-->
<!--{% for error in child.non_field_errors %}-->
<!--<p class="alert alert-danger alert-dismissable">-->
    <!--<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>-->
    <!--{{ error }}-->
<!--</p>-->
<!--{% endfor %}-->
<!--{% endif %}-->
<form action="{{ child.action }}" method="{{ child.method }}" role="form" id="{{child.id}}">
    {% csrf_token %}
    {# Include the hidden fields #}
    {% for hidden in child.hidden_fields %}
    {{ hidden }}
    {% endfor %}
    {% if child.fieldsets %}
    {% for fieldset in child.fieldsets %}
    <fieldset class="{{ fieldset.classes }}">
        {% if fieldset.legend %}
        <legend>{{ fieldset.legend }}</legend>
        {% endif %}
        {% if fieldset.description %}
        <p class="description text-muted">{{ fieldset.description }}</p>
        {% endif %}
        {% for field in fieldset %}
        <div class="form-group{% if field.errors|length > 0 %} has-error {% endif %} has-feedback">
            {% if field|get_field_type == 'ChecakboxInput' %}
            <label for='{{ field.id_for_label }}' class="checkbox">{{field}}{{ field.label }}</label>
                {% if field.errors|length > 0 %}
                <span class="glyphicon glyphicon-remove form-control-feedback"></span>
                <div class="alert alert-danger">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    {% for error in field.errors %} {{ error }} {% endfor %}
                </div>
                {% endif %}
            {% else %}
            <label for='{{ field.id_for_label }}' class="control-label">{{ field.label }}</label>
            {{field|addcss:"form-control"}}
            <div class="field_error"></div>
                {% if field.errors|length > 0 %}<span
                    class="glyphicon glyphicon-remove form-control-feedback"></span>

                <div class="alert alert-danger">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                    {% for error in field.errors %} {{ error }} {% endfor %}
                </div>
                {% endif %}
            {% endif %}
        </div>
        {% endfor %}
    </fieldset>
    {% endfor %}

    {% else %}
    {% for field in child %}
        {% if field.is_hidden %}
            {{ field }}
        {% else %}
        <div class="form-group{% if field.errors|length > 0 %} has-error {% endif %} has-feedback">
            {% if field|get_field_type == 'CheckboxInput' %}
            <label for='{{ field.id_for_label }}' class="checkbox">{{field}}{{ field.label }}</label>
            {% if field.errors|length > 0 %}
            <span class="glyphicon glyphicon-remove form-control-feedback"></span>
            <div class="alert alert-danger">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                {% for error in field.errors %} {{ error }} {% endfor %}
            </div>
            {% endif %}
            {% else %}
            <label for='{{ field.id_for_label }}' class="control-label">{{ field.label }}</label>
            {{field|addcss:"form-control"}}
            <div class="field_error"></div>
            {% if field.errors|length > 0 %}<span
                class="glyphicon glyphicon-remove form-control-feedback"></span>

            <div class="alert alert-danger">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                {% for error in field.errors %} {{ error }} {% endfor %}
            </div>
            {% endif %}
            {% endif %}
        </div>
        {% endif %}
    {% endfor %}
    {% endif %}
    <input type="submit" value="{{ child.submit_button_value }}" {% if child.confirmation %}data-confirmation="true"{% endif %} class="btn btn-{{ child.submit_button_style }}">
</form>