{% load crispy_forms_field crispy_forms_foundation_field %}

{% if field.is_hidden %}
    {{ field }}
{% else %}
    <div id="div_{{ field.auto_id }}" class="holder{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field|is_checkbox %} checkbox{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}">{% spaceless %}

        {% if field.label %}
            {% if field|is_checkbox %}
                {% crispy_field field %}
            {% endif %}

            <label{% if not fake_field %} for="{{ field.id_for_label }}"{% endif %}{% if field.errors and form_show_errors or field.field.required %} class="{% if field.field.required %}required{% endif %}{% if field.errors and form_show_errors %} is-invalid-label{% endif %}"{% endif %}>
                {{ field.label|safe }}{% if field.field.required %}<span class="asterisk">*</span>{% endif %}
            </label>
        {% endif %}

        {% if field|is_checkboxselectmultiple %}
            {% include 'foundation-6/layout/checkboxselectmultiple.html' %}
        {% endif %}

        {% if not field|is_checkbox and not field|is_checkboxselectmultiple %}
            {% crispy_field field %}
        {% endif %}

        {% if field.field.abide_msg %}
            <span id="abide_error_{{ field.auto_id }}" class="form-error{% if form_show_errors and not field.errors|length_is:"0" %} compact{% endif %}" data-form-error-for="{{ field.id_for_label }}">
                {{ field.field.abide_msg }}
            </span>
        {% endif %}

        {% if form_show_errors %}
            {% for error in field.errors %}
                <span id="error_{{ forloop.counter }}_{{ field.auto_id }}" class="form-error is-visible{% if not forloop.last %} compact{% endif %}">
                    {{ error }}
                </span>
            {% endfor %}
        {% endif %}

        {% if field.help_text %}
            <p id="helptext_{{ field.auto_id }}" class="help-text">{{ field.help_text|safe }}</p>
        {% endif %}
    {% endspaceless %}</div>
{% endif %}
