flask-base/templates/_formhelpers.html
2018-03-31 18:26:40 +02:00

57 lines
2.0 KiB
HTML

{% macro render_field(field, prefix=None, suffix=None, layout=True, label=True) %}
{% if field.type == 'HiddenField' %}
{{ field(**kwargs) }}
{% else %}
{% if layout %}
<div class="form-group{% if field.errors %} has-error{% endif %}">
{% if field.type == 'BooleanField' %}
<div class="col-xs-3"></div>
{% elif label %}
{{ field.label(class_='col-xs-3 control-label') }}
{% endif %}
<div class="col-xs-9">
{% endif %}
{{ render_field_inner(field, prefix, suffix, label=label, **kwargs) }}
{% if layout %}
</div>
</div>
{% endif %}
{% endif %}
{% endmacro %}
{% macro render_field_inner(field, prefix=None, suffix=None, label=True) %}
{% if field.type == 'BooleanField' %}<div class="checkbox"><label for="{{ field.id }}">{% endif %}
{% if prefix or suffix %}<div class="input-group">{% endif %}
{% if prefix %}<span class="input-group-addon">{{ prefix }}</span>{% endif %}
{% if field.type == 'BooleanField' %}
{{ field(**kwargs) }} {% if label %}{{ field.label.text }}{% endif %}
{% else %}
{{ field(class_='form-control', **kwargs) }}
{% endif %}
{% if suffix %}<span class="input-group-addon">{{ suffix }}</span>{% endif %}
{% if prefix or suffix %}</div>{% endif %}
{% if field.description %}
<span class="help-block">{{ field.description }}</span>
{% endif %}
{% if field.errors %}
{% for error in field.errors %}
<span class="help-block">{{ error }}</span>
{% endfor %}
{% endif %}
{% if field.type == 'BooleanField' %}</label></div>{% endif %}
{% endmacro %}
{% macro render_submit(label='Submit', class_='btn btn-primary', layout=True) %}
{% if layout %}
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
{% endif %}
<button type="submit" class="{{ class_ }}">{{ label }}</button>
{% if layout %}
</div>
</div>
{% endif %}
{% endmacro %}