Improve forms for user creation an deletion
parent
8d6a4cb654
commit
398e7c1183
@ -1,5 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block box_content %}
|
||||
{{ wtf.quick_form(form) }}
|
||||
{{ macros.form(form) }}
|
||||
{% endblock %}
|
||||
|
@ -0,0 +1,57 @@
|
||||
{% macro form_errors(form) %}
|
||||
{% if form.errors %}
|
||||
{% for fieldname, errors in form.errors.items() %}
|
||||
{% if bootstrap_is_hidden_field(form[fieldname]) %}
|
||||
{% for error in errors %}
|
||||
<p class="error">{{error}}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro form_fields(fields, prepend='', append='', label=True) %}
|
||||
{% set width = (12 / fields|length)|int %}
|
||||
<div class="form-group">
|
||||
<div class="row">
|
||||
{% for field in fields %}
|
||||
<div class="col-lg-{{ width }} col-xs-12 {{ 'has-error' if field.errors else '' }}">
|
||||
{{ field.label if label else '' }}
|
||||
{% if field.errors %}
|
||||
{% for error in field.errors %}
|
||||
<p class="help-block inline">{{ error }}</p>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if prepend or append %}<div class="input-group">{% endif %}
|
||||
{{ prepend|safe }}
|
||||
{{ field(class_="form-control", **kwargs) }}
|
||||
{{ append|safe }}
|
||||
{% if prepend or append %}</div>{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro form_field(field) %}
|
||||
{% if field.type == 'SubmitField' %}
|
||||
{{ form_fields((field,), label=False, class="btn btn-default", **kwargs) }}
|
||||
{% elif field.type == 'HiddenField' %}
|
||||
{{ form_fields((field,), label=False, **kwargs) }}
|
||||
{% else %}
|
||||
{{ form_fields((field,), **kwargs) }}
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro form(form) %}
|
||||
<form class="form" method="post" role="form">
|
||||
{{ form.hidden_tag() }}
|
||||
{% for field in form %}
|
||||
{% if bootstrap_is_hidden_field(field) %}
|
||||
{{ field() }}
|
||||
{% else %}
|
||||
{{ form_field(field) }}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</form>
|
||||
{% endmacro %}
|
Loading…
Reference in New Issue