{% load i18n %}
{% load bootstrap_tags %}

{% if form.non_field_errors %}
    <div class="alert alert-danger">{{ form.non_field_errors }}</div>
{% endif %}

{% csrf_token %}
{% for hidden in form.hidden_fields %}
    {{ hidden }}
{% endfor %}

{% for field in form.visible_fields %}
    <div class="form-group {% if field.errors %}has-errors{% endif %} row">
        <label class="control-label font-weight-bold col-{{ fold_class }}-{{ size_left }}"
               for="{{ field.id_for_label }}">
            {% if not field|fieldtype_is:'CheckboxInput' %}
                {{ field.label }}
            {% endif %}
        </label>
        <div class="col-{{ fold_class }}-{{ size_right }}">
            {% if field|fieldtype_is:'RadioSelect' %}
                {% for choice in field %}
                    <label class="radio-inline">
                        {{ choice.tag }}
                        {{ choice.choice_label }}
                    </label>
                {% endfor %}
            {% elif field|fieldtype_is:'CheckboxInput' %}
                <div class="checkbox">
                    <label>
                        {{ field }} {{ field.label }}
                    </label>
                </div>
            {% elif field|fieldtype_is:'CheckboxSelectMultiple' %}
                {% for choice in field %}
                    <div class="checkbox">
                        <label>
                            {{ choice }} {{ choice.label }}
                        </label>
                    </div>
                {% endfor %}
            {% else %}
                {{ field|add_form_control }}
            {% endif %}
            {% for error in field.errors %}
                <div class="text-danger">{{ error }}</div>
            {% endfor %}
        </div>
        {% if field.help_text %}
        <p id="help-{{ field.id_for_label }}"
           class="offset-{{ fold_class }}-{{ size_left }} col-{{ fold_class }}-{{ size_right }} text-muted">
            {{ field.help_text|safe|linebreaksbr }}
        </p>
        {% endif %}
    </div>
{% endfor %}
{% if button %}
    <div class="form-group">
        <div class="offset-{{ fold_class }}-{{ size_left }} col-{{ fold_class }}-{{ size_right }}">
            <button class="btn btn-primary" type="submit">{% trans button %}</button>
        </div>
    </div>
{% endif %}
