1
0
mirror of https://github.com/Yubico/yubiadmin.git synced 2025-02-20 14:54:30 +01:00
yubiadmin/templates/form.html
2013-04-25 14:48:24 +02:00

93 lines
2.3 KiB
HTML

{%- macro form_field_label(field) -%}
<label for="{{ field.id }}">{{ field.label.text }}
{%- if field.flags.required -%}
<abbr title="This field is required!">*</abbr>
{%- endif %}</label>
{% endmacro %}
{%- macro form_field_description(field) -%}
{% if field.description %}
<span class="descr">{{ field.description }}</span>
{% endif %}
{%- endmacro -%}
{%- macro form_field_errors(field) -%}
{% if field.errors %}
<div>
{%- for error in field.errors -%}
<span class="label important">{{ error }}</span>
{%- endfor -%}
</div>
{% endif %}
{%- endmacro -%}
{%- macro form_field_boolean(field) -%}
<div class="input">
<label>
{{ field(**kwargs) }}
<span>{{ field.label.text }}</span>
{{ form_field_description(field) }}
{{ form_field_errors(field) }}
</label>
</div>
{%- endmacro -%}
{%- macro form_field(field, attrs={}) -%}
<div class="clearfix">
{% if field.type == 'HiddenField' %}
{{ field() }}
{% else %}
{% if field.type == 'BooleanField' %}
{{ form_field_boolean(field, **attrs) }}
{% else %}
{{ form_field_label(field) }}
<div class="input" id="{{field.id}}-div">
{% if field.type == 'RadioField' %}
{{ field(class='radio-group', **attrs) }}
{% elif field.type == 'IntegerField' %}
{{ field(class='input-mini', **attrs) }}
{% else %}
{{ field(**attrs) }}
{% endif %}
{{ form_field_description(field) }}
{{ form_field_errors(field) }}
</div>
{% endif %}
{% endif %}
</div>
{%- endmacro -%}
{%- macro form_fieldset(fieldset) -%}
<fieldset>
{% if fieldset.legend %}
<legend>{{fieldset.legend}}</legend>
{% endif %}
{% for field in fieldset %}
{% if field.type == 'HiddenField' %}
{{ field() }}
{% else %}
{% if fieldset.attrs is defined and fieldset.attrs[field.id] is defined %}
{{ form_field(field, fieldset.attrs[field.id]) }}
{% else %}
{{ form_field(field) }}
{% endif %}
{% endif %}
{% endfor %}
</fieldset>
{%- endmacro -%}
{%- macro render_form(fieldsets, action) -%}
<form action="{{ action }}" method="post">
{% for fieldset in fieldsets %}
{{ form_fieldset(fieldset) }}
{% endfor %}
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Save">
&nbsp;
<button type="reset" class="btn">Reset form</button>
</div>
</form>
{%- endmacro -%}
{{ render_form(fieldsets, target) }}