{% load form_tags %}

{% comment %}
Make the field widget type available to templates so we can mark-up
checkboxes differently to other widgets.
{% endcomment %}
{% annotate_form_field field %}

<div class="control-group {% if field.errors %}error{% endif %}">
    {% if field.is_hidden %}
        {{ field }}
    {% else %}
		{# Check if field is a checkbox as we mark these up differently #}
		{% if field.widget_type == 'CheckboxInput' %}
			<div class="controls">
			<label for="{{ field.auto_id }}" class="checkbox {% if field.field.required %}required{% endif %}">{{ field.label }}{% if field.field.required %} <span>*</span>{% endif %}
    				{{ field }}
    			</label>
				{% for error in field.errors %}
                    <span class="help-block"><i class="icon-exclamation-sign"></i> {{ error }}</span>
				{% endfor %}
				{% if field.help_text %}
					<span class='help-block'>
						{# We allow HTML within form help fields #}
						{{ field.help_text|safe }}
					</span>
				{% endif %}
			</div>
		{% else %}
			<label for="{{ field.auto_id }}" class="control-label {% if field.field.required %}required{% endif %}">{{ field.label }}{% if field.field.required %} <span>*</span>{% endif %}</label>
			<div class="controls">
				{{ field }}
				{% for error in field.errors %}
					<span class="help-block"><i class="icon-exclamation-sign"></i> {{ error }}</span>
				{% endfor %}
				{% if field.help_text %}
					<span class='help-block'>
						{# We allow HTML within form help fields #}
						{{ field.help_text|safe }}
					</span>
				{% endif %}
			</div>
		{% endif %}
    {% endif %}
</div>
