{% load form_helpers %}

<div class="form-group{% if field.errors %} has-error{% endif %}">
    {% if field|widget_type == 'checkboxinput' %}
        <div class="col-md-9 col-md-offset-3">
            <div class="checkbox{% if field.errors %} has-error{% endif %}">
                <label for="{{ field.id_for_label }}">
                    {{ field }} {{ field.label }}
                </label>
                {% if field.help_text %}
                    <span class="help-block">{{ field.help_text|safe }}</span>
                {% endif %}
            </div>
            {% if bulk_nullable %}
                <label class="checkbox-inline">
                    <input type="checkbox" name="_nullify" value="{{ field.name }}" /> Set null
                </label>
            {% endif %}
    {% elif field|widget_type == 'textarea' and not field.label %}
        <div class="col-md-12">
            {{ field }}
            {% if bulk_nullable %}
                <label class="checkbox-inline">
                    <input type="checkbox" name="_nullify" value="{{ field.name }}" /> Set null
                </label>
            {% endif %}
            {% if field.help_text %}
                <span class="help-block">{{ field.help_text|safe }}</span>
            {% endif %}
    {% else %}
        <label class="col-md-3 control-label{% if field.field.required %} required{% endif %}" for="{{ field.id_for_label }}">{{ field.label }}</label>
        <div class="col-md-9">
            {{ field }}
            {% if bulk_nullable %}
                <label class="checkbox-inline">
                    <input type="checkbox" name="_nullify" value="{{ field.name }}" /> Set null
                </label>
            {% endif %}
            {% if field.help_text %}
                <span class="help-block">{{ field.help_text|safe }}</span>
            {% endif %}
    {% endif %}
    {% if field.errors %}
        <ul>
            {% for error in field.errors %}
                {# Embed an HTML comment indicating the error for extraction by tests #}
                <!-- FORM-ERROR {{ field.name }}: {{ error }} -->
                <li class="text-danger">{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}
</div>
</div>
