
{% macro render_field(field, label_visible=true, help='', R='') %}

    <div class="form-group {% if field.errors %}has-error{% endif %} {{ kwargs.pop('class_', '') }}">
        {% if (field.type != 'HiddenField' or field.type !='CSRFTokenField') and label_visible %}
        <div class="col-sm-6 control-label">
            <label for="{{ field.id }}">{{ field.label }} {{R|safe}}</label>
        </div>
            
        {% endif %}
    <div class="col-md-1">
        {%if (help!='')%} <span data-toggle="tooltip" rel='tooltip' data-placement="right" title="{{help}}"><i class="fa fa-info-circle"></i></span> {% endif %}
    </div>
        <div class="col-md-5">
            {{ field(class_='form-control', **kwargs) }}
            {% if field.errors %}
                {% for e in field.errors %}
                    <p class="help-block">{{ e|safe }}</p>
                {% endfor %}
            {% endif %}
        </div>
    </div>
{% endmacro %}

{% macro render_checkbox_field(field) %}
<div class="form-group">
    <div class="col-sm-offset-1 col-sm-11">
        <div class="checkbox">
            <label>
                {{ field(type='checkbox', **kwargs) }} {{ field.label }}
            </label>
        </div>
    </div>
</div>
{% endmacro %}
{% macro render_radio_field(field, help='') %}
<div class="form-group">
    <div class="col-sm-6 control-label">
        <label for="{{field.id}}">{{field.label}}
            {% if field.errors %}
                {% for e in field.errors %}
                    <p class="help-block">{{ e|safe }}</p>
                {% endfor %}
            {% endif %}
        </label>
    </div>
    <div class="col-md-1">
        {%if (help!='')%} <span data-toggle="tooltip" rel='tooltip' data-placement="right" title="{{help}}"><i class="fa fa-info-circle"></i></span> {% endif %}
    </div>
    <div class="col-md-5">
        {% for value, label, _ in field.iter_choices() %}
        <label class="radio-inline"> <input  {% if _ %}checked="true"{% endif %}  type="radio" name="{{ field.id }}" id="{{ field.id }}" value="{{ value }}">{{ label }} </label>
        {% endfor %}
    </div>
</div>
{% endmacro %}

{% macro render_form(form, action_url='', action_text='Submit', class_='', btn_class='btn btn-default') %}

    <form method="POST" action="{{ action_url }}" 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_field(f) }}
                {% elif f.type == 'RadioField' %}
                    {{ render_radio_field(f) }}
                {% else %}
                    {{ render_field(f) }}
                {% endif %}
            {% endfor %}
        {% endif %}
        <button type="submit" class="{{ btn_class }}">{{ action_text }} </button>
    </form>
{%- endmacro %}
