Created
January 29, 2015 17:36
-
-
Save mcescalante/a87aa5f715d15b83541b to your computer and use it in GitHub Desktop.
jinja macro for rendering form field errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% macro with_errors(field) %} | |
<div class="form_field"> | |
{% if field.errors %} | |
{% set css_class = 'has_error ' + kwargs.pop('class', '') %} | |
{{ field(class=css_class, **kwargs) }} | |
<ul class="errors">{% for error in field.errors %}<li>{{ error|e }}</li>{% endfor %}</ul> | |
{% else %} | |
{{ field(**kwargs) }} | |
{% endif %} | |
</div> | |
{% endmacro %} | |
Usage: {{ with_errors(form.field, style='font-weight: bold') }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment