form_macros.html 1.1 KB

123456789101112131415161718192021222324
  1. {% macro display_errors(errors) -%}
  2. {%- if errors -%}
  3. <span class="help-inline error-list">
  4. <strong>{%- trans ercnt=errors|count %}Error:{% pluralize %}Errors:{% endtrans -%}</strong>{#
  5. #}<ul class="inline" style="display: inline;">
  6. {%- for e in errors -%}
  7. <li>{{ e }}</li>
  8. {%- endfor -%}
  9. </ul>
  10. </span>
  11. {%- endif -%}
  12. {%- endmacro %}
  13. {% macro render_field(field) -%}
  14. <div class="control-group{% if field.flags.required %} required{%endif%}{% if field.errors %} error{% endif %}">
  15. <label class="control-label" for="{{ field.name }}">{{ field.label.text|capitalize }}</label>
  16. <div class="controls">
  17. {{ field(placeholder=field.description.0, **kwargs) if field.description.0 else field(**kwargs) }}
  18. {{ display_errors(field.errors) }}
  19. {%- if field.description.1 -%}
  20. <span class="help-block">{{ field.description.1|safe }}</span>
  21. {%- endif %}
  22. </div>
  23. </div>
  24. {%- endmacro %}