{% load logger jsmin variable get_attr %}

{% block form_common_error %}
    {% jsrmln %}
        {% if form.errors %}
            <div class="alert alert-error">
                <strong style="display: block">Please correct the errors.</strong>
                {% if form.non_field_errors %}
                    <ol>
                        {% for err in form.non_field_errors %}
                            <li><span>{{ err }}</span></li>
                        {% endfor %}
                    </ol>
                {% endif %}
            </div>
        {% endif %}
    {% endjsrmln %}
{% endblock %}

<form class="form-{{ layout }}" id="{{ form_id }}" action="{{ form_action }}" {% if form.is_multipart %}enctype="multipart/form-data" {% endif %}
      method="{{ method }}" accept-charset="utf-8">

    {% for field in form %}
        {% assign form_field field.field %}
        {% if form_field.html_before %}{{ form_field.html_before }}{% endif %}
        <div class="control-group{% if field.errors %} error{% endif %}" id="container_{{ field.id_for_label }}">

            <div class="control-label">
                <label class="control-label" for="{{ field.id_for_label }}">{{ field.label }} : </label>
            </div>

            <div class="controls">

                {% if form_field.has_prepend or form_field.has_append %}
                    <div class="{% if form_field.has_prepend %}input-prepend {% endif %}{% if form_field.has_append %}input-append {% endif %}">
                {% endif %}

                {% if form_field.has_prepend %}{{ form_field.prepend_text }}{% endif %}
                {{ field }}
                {% if form_field.has_append %}{{ form_field.append_text }}{% endif %}
                {% if field.errors %}
                    {% for error_msg in field.errors %}
                        <label class="help-block" for="{{ field.id_for_label }}">
                            {{ error_msg }}
                        </label>
                    {% endfor %}
                {% else %}
                    {% if field.help_text %}
                        <label for="{{ field.id_for_label }}">
                            <span class="help-block">{{ field.help_text }}</span>
                        </label>
                    {% endif %}
                {% endif %}
                {% if form_field.has_prepend or form_field.has_append %}
                    </div>
                {% endif %}

            </div>
        </div>
        {% if form_field.html_after %}{{ form_field.html_after }}{% endif %}
    {% endfor %}

    {% block form_submit %}
        <div class="control-group">
            <div class="controls">
                <button type="submit" class="btn btn-{{ button_color }}">{{ form_submit|default:"Submit" }}</button>
            </div>
        </div>
    {% endblock %}

    {% if csrf_token_html %}
        {{ csrf_token_html }}
    {% else %}
        {% csrf_token %}
    {% endif %}

</form>