Skip to content
Snippets Groups Projects
Commit 9b319027 authored by YSelf Tool's avatar YSelf Tool
Browse files

Added macros.html

parent a621ea40
No related branches found
No related tags found
No related merge requests found
{% macro render_field(field, label_visible=true) -%}
{{ field(id=field.id, title=field.description, **kwargs) }}
{% if field.errors %}
{% for e in field.errors %}
<p class="help-block">{{ e }}</p>
{% endfor %}
{% endif %}
{%- endmacro %}
{% macro render_stringfield(field) -%}
<div class="mdl-textfield mdl-js-textfield">
<input id="{{ field.id }}" name="{{ field.id }}" class="mdl-textfield__input" type="text" />
<label class="mdl-textfield__label" for="{{ field.id }}">{{ field.label.text }}</label>
{% if field.errors %}
{% for e in errors %}
<div class="mdl-card__supporting-text">
{{ e }}
</div>
{% endfor %}
{% endif %}
</div>
{%- endmacro %}
{% macro render_passwordfield(field) -%}
<div class="mdl-textfield mdl-js-textfield">
<input id="{{ field.id }}" name="{{ field.id }}" class="mdl-textfield__input" type="password" />
<label class="mdl-textfield__label" for="{{ field.id }}">{{ field.label.text }}</label>
{% if field.errors %}
{% for e in errors %}
<div class="mdl-card__supporting-text">
{{ e }}
</div>
{% endfor %}
{% endif %}
</div>
{%- endmacro %}
{% macro render_booleanfield(field) -%}
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="{{ field.id }}">
<input type="checkbox" id="{{ field.id }}" name="{{ field.id }}" class="mdl-checkbox__input" />
<span class="mdl-checkbox__label">{{ field.label.text }}</span>
</label>
{%- endmacro %}
{% macro render_csrftokenfield(field, kwargs) -%}
{{ field(title=field.description, **kwargs) }}
{%- endmacro %}
{% macro render_form(form, action_url="", title=None, action_text="Submit", class_="mdl-card mdl-shadow--2dp", title_class="mdl-card__title", title_next_class="mdl-card__title-text", content_class="mdl-card__supporting-text", action_class="mdl-card__actions", btn_class="mdl-button mdl-js-button mdl-button--raised mdl-button-colored") -%}
<div class="{{ class_ }}">
<form method="POST" action="{{ action_url }}">
<div class="{{ title_class }}">
<h2 class="{{ title_text_class}}">{{ title if title is not none else action_text }}</h2>
</div>
<div class="{{ content_class }}">
{% for f in form %}
{% if f.type == "StringField" %}
{{ render_stringfield(f) }}
{% elif f.type == "PasswordField" %}
{{ render_passwordfield(f) }}
{% elif f.type == "BooleanField" %}
{{ render_booleanfield(f) }}
{% elif f.type == "CSRFTokenField" %}
{{ render_csrftokenfield(f, kwargs) }}
{% else %}
{{ f.type }}
{{ render_field(f) }}
{% endif %}
{% endfor %}
{% endfor %}
</div>
<div class="{{ action_class }}">
<button type="submit" class="{{ btn_class }}">{{ action_text }}</button>
</div>
</form>
</div>
{%- endmacro %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment