Add macro
This commit is contained in:
parent
6b49829c0f
commit
3569adfd13
19
templates/helpers/_forms.html
Normal file
19
templates/helpers/_forms.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{% macro generate_fields(form) -%}
|
||||||
|
{% for field in form %}
|
||||||
|
{% if field.type != 'CSRFTokenField' %}
|
||||||
|
<div class="form-group{%if field.errors %} has-error{% endif %}">
|
||||||
|
{{ field.label }}
|
||||||
|
{% if field.type in ('StringField', 'PasswordField') %}
|
||||||
|
{{ field(class='form-control') }}
|
||||||
|
{% else %}
|
||||||
|
{{ field() }}
|
||||||
|
{% endif %}
|
||||||
|
{% for error in field.errors %}
|
||||||
|
<span class="help-block">{{ error }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
{{ field() }}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{%- endmacro %}
|
@ -1,3 +1,4 @@
|
|||||||
|
{% from 'helpers/_forms.html' import generate_fields with context %}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
@ -3,18 +3,7 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>Edit contact</h1>
|
<h1>Edit contact</h1>
|
||||||
<form method="post">
|
<form method="post">
|
||||||
{{ form.csrf_token }}
|
{{ generate_fields(form) }}
|
||||||
{% for field in form %}
|
|
||||||
{% if field.label.text != 'CSRF Token' %}
|
|
||||||
<div class="form-group{%if field.errors %} has-error{% endif %}">
|
|
||||||
{{ field.label }}
|
|
||||||
{{ field(class='form-control') }}
|
|
||||||
{% for error in field.errors %}
|
|
||||||
<span class="help-block">{{ error }}</span>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
<input type="submit" class="btn btn-success" value="Save">
|
<input type="submit" class="btn btn-success" value="Save">
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -3,18 +3,7 @@
|
|||||||
{% block body %}
|
{% block body %}
|
||||||
<h1>New contact</h1>
|
<h1>New contact</h1>
|
||||||
<form action="{{ url_for('new_contact') }}" method="post">
|
<form action="{{ url_for('new_contact') }}" method="post">
|
||||||
{{ form.csrf_token }}
|
{{ generate_fields(form) }}
|
||||||
{% for field in form %}
|
|
||||||
{% if field.label.text != 'CSRF Token' %}
|
|
||||||
<div class="form-group{%if field.errors %} has-error{% endif %}">
|
|
||||||
{{ field.label }}
|
|
||||||
{{ field(class='form-control', value='') }}
|
|
||||||
{% for error in field.errors %}
|
|
||||||
<span class="help-block">{{ error }}</span>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
<input type="submit" class="btn btn-success" value="Add">
|
<input type="submit" class="btn btn-success" value="Add">
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
Loading…
Reference in New Issue
Block a user