{# render_bs3_field(field,label=true) #}
{% macro render_field(field,label=true) %}
    <div class="form-group {% if field.errors %}has-error{% endif %} {{ kwargs.pop('class_','') }}">
        {% if (field.type != 'HiddenField' and field.type != 'CSRFTokenField') and label %}
            <label for="{{ field.id }}" class="control-label">{{ field.label }}{% if field.flags.required %} *{% endif %}</label>
        {% endif %}
        {{ field(class_='form-control',**kwargs) }}
        {% if field.errors %}
            {% for e in field.errors %}
                <p class="help-block">{{ e }}</p>
            {% endfor %}
        {% endif %}
    </div>
{% endmacro %}

{% macro render_checkbox(field) %}
    <div class="checkbox">
        <label>
                {{ field(type='checkbox',**kwargs) }} {{ field.label }} {% if field.flags.required %}*{% endif %}
        </label>
    </div>
{% endmacro %}

{% macro render_radio(field) %}
    {% for value,label,_ in field.iter_choices() %}
        <div class=radio>
            <label>
                <input type=radio name="{{ field.id }}" id="{{ field.id }}" value="{{ value }}">{{ label }} {% if field.flags.required %}*{% endif %}
            </label>
        </div>
    {% endfor %}
{% endmacro %}

{% macro render_form(form,action='',action_text='Submit',class_='',btn_class='btn btn-default') %}
    <form method="POST" action="{{ action }}" role=form class="{{ class_ }}">
        {{ form.hidden_tag() if form.hidden_tag }}
        {% if caller %}
            {{ caller() }}
        {% else %}
            {% for f in form %}
                {% if f.type == 'BooleanField' %}
                    {{ render_checkbox(f) }}
                {% elif f.type == 'RadioField' %}
                    {{ render_radio(f) }}
                {% else %}
                    {{ render_field(f) }}
                {% endif %}
            {% endfor %}
        {% endif %}
        <button type="submit" class="{{ btn_class }}">{{ action_text }}</button>
    </form>
{% endmacro %}

