{% macro render_field_checkbox(form, field, classes) -%}
  <div class="{{ classes.single_value }}">
    <div class="checkbox">
      {% if field.auto_id %}
        <label {% if field.field.required %}class="{{ form.required_css_class or 'required' }}"{% endif %}>
          {{ field|safe }} <span>{{ field.label }}</span>
        </label>
      {% endif %}
      {% for error in field.errors %}
        <span class="help-block {{ form.error_css_class or 'error-msg' }}">{{ error }}</span>
      {% endfor %}
      {% if field.help_text %}
        <p class="help-block">
          {{ field.help_text|safe }}
        </p>
      {% endif %}
    </div>
  </div>
{%- endmacro %}

{% macro render_field_radio(form, field, classes) -%}
  {% if field.auto_id %}
    <label class="control-label {{ classes.label }}{% if field.field.required %} {{ form.required_css_class or 'required' }}{% endif %}">{{ field.label }}</label>
  {% endif %}
  <div class="{{ classes.value }}">
    {% for choice in field %}
      <div class="radio">
        <label>
          {{ choice.tag()|safe }}
          {{ choice.choice_label }}
        </label>
      </div>
    {% endfor %}
    {% for error in field.errors %}
      <span class="help-block {{ form.error_css_class or 'error-msg' }}">{{ error }}</span>
    {% endfor %}

    {% if field.help_text %}
    <p class="help-block">
      {{ field.help_text|safe }}
    </p>
    {% endif %}
  </div>
{%- endmacro %}

{% macro render_field_standard(form, field, classes) -%}
  {% if field.auto_id %}
    <label class="control-label {{ classes.label }} {% if field.field.required %}{{ form.required_css_class or 'required' }}{% endif %}" for="{{ field.auto_id }}">{{ field.label }}</label>
  {% endif %}

  <div class="{{ classes.value }}{% if field is multiple_checkbox_field %} multiple-checkbox{% endif %}">
    {{ field|safe }}
    {% for error in field.errors %}
      <span class="help-block {{ form.error_css_class or 'error-msg' }}">{{ error }}</span>
    {% endfor %}
    {% if field.help_text %}
      <p class="help-block">
        {{ field.help_text|safe }}
      </p>
    {% endif %}
  </div>
{%- endmacro %}

{% macro render(form, field, classes) -%}
<div class="form-group{% if field.errors %} has-error{% endif %}">
  {% if field is checkbox_field %}
    {{ render_field_checkbox(form, field, classes) }}
  {% elif field is radio_field %}
    {{ render_field_radio(form, field, classes) }}
  {% else %}
    {{ render_field_standard(form, field, classes) }}
  {% endif %}
</div>
{%- endmacro %}
