Skip to content

Instantly share code, notes, and snippets.

@stephane
Created November 23, 2021 11:58
Show Gist options
  • Save stephane/822ecd7982c484846af536e991608f27 to your computer and use it in GitHub Desktop.
Save stephane/822ecd7982c484846af536e991608f27 to your computer and use it in GitHub Desktop.
{% macro field_label(field) -%}
<label class="form-label" for="{{ field.id }}">
{{ field.label.text }} {% if field.flags.required %}*{% endif %}
</label>
{%- endmacro %}
{% macro field(field, group_class=None, space_field_class="") -%}
<div class="form-group{% if group_class %} {{ group_class}}{% endif %}">
{{ field_label(field) }}
{% if field.errors %}
{{ field(class="form-control is-invalid" + space_field_class, **kwargs) }}
<div class="invalid-feedback">{% for error in field.errors %}{{ error|e }} {% endfor %}</div>
{% else %}
{{ field(class="form-control" + space_field_class, **kwargs) }}
{% endif %}
{% if field.description %}<div class="form-text"> {{ field.description }}</div>{% endif %}
</div>
{%- endmacro %}
{% macro show_error_message(error_message) -%}
{% if error_message %}<div class="invalid-feedback d-block mb-2">{{ error_message }}</div>{% endif %}
{%- endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment