{% load i18n bootstrap_form %}

{% for field in fields %}
    {% if field.is_hidden %}
        {{ field }}
    {% else %}
        <div class="control-group clearfix {{ field.name }} {{ field.field.widget|klass|lower }} {% if field.errors %}error{% endif %}">
            {% if field.field.widget|klass == 'CheckboxInput'%}
                {% if field.label %}
                    <label class="control-label" for="id_{{ field.name }}">
                        {{ field }}
                        {{ field.label }}

                        {% if field.field.required %}
                            <span class="required">*</span>
                        {% endif %}

                        {% if field.help_text %}
                            <a class="help-block" data-content="{{ field.help_text }}" title="{{ field.label }}">
                                {% trans 'Display help text' %}
                            </a><!-- /.help-block -->
                        {% endif %}
                    </label>
                {% endif %}

                {% if field.errors %}
                    <div class="controls">
                        <span class="help-inline">
                            <span class="inner">
                                {% for error in field.errors %}
                                    <span class="line">
                                        <span class="cell">{{ error|escape }}</span><!-- /.cell -->
                                     </span><!-- /.line -->
                                {% endfor %}
                            </span><!-- /.inner -->
                        </span>
                    </div><!-- /.controls -->
                {% endif %}
            {% else %}
                {% if field.label %}
                    <label class="control-label" for="id_{{ field.name }}">
                        {{ field.label }}

                        {% if field.field.required %}
                            <span class="required">*</span>
                        {% endif %}
                    </label>
                {% endif %}

                <div class="controls">
                    <div class="{% if field.field.widget.attrs.append %}input-append{% endif %}">
                        {{ field }}

                        {% if field.field.widget.attrs.append %}
                            <span class="add-on">
                                {{ field.field.widget.attrs.append }}
                            </span>
                        {% endif %}

                        {% if field.help_text %}
                            <a class="help-block" data-content="{{ field.help_text }}" title="{{ field.label }}">
                                {% trans 'Display help text' %}
                            </a><!-- /.help-block -->
                        {% endif %}
                    </div>

                    {% if field.errors %}
                        <span class="help-inline">
                            <span class="inner">
                                {% for error in field.errors %}
                                    <span class="line">
                                        <span class="cell">
                                            {{ error|escape }}
                                        </span><!-- /.cell -->
                                    </span><!-- /.line -->
                                {% endfor %}
                            </span><!-- /.inner -->
                        </span>
                    {% endif %}
                </div><!-- /.controls -->
            {% endif %}
        </div><!-- /.control-group -->
    {% endif %}
{% endfor %}