{% from 'message_box.html' import message_box %} {% macro _render_errors(errors) -%} {%- endmacro %} {% macro form_header(form, method='post', action='', orientation='horizontal', id=none, classes='', multipart=false, i_form=true, no_ajax=false, disable_if_locked=true, extra_attrs={}) -%}
{% if form.meta.csrf -%} {{ form.csrf_token() }} {% endif %} {% for field in _iter_form_fields(form, hidden_fields=true, skip=('csrf_token',)) %} {{ field() }} {% endfor %} {%- endmacro %} {% macro form_row_static(label='', content=none, single_row=true, skip_label=false) -%}
{% if not skip_label %}
{% if label %} {% endif %}
{% endif %}
{{ content or caller() }}
{%- endmacro %} {% macro form_field(field, field_classes, widget_attrs={}, disabled=none, hide_description=false) -%}
{{ _render_field(field, widget_attrs, disabled) }} {% if field.widget.input_type == 'checkbox' %}
{{ field.label() }}
{% endif %} {%- if caller is defined -%} {{ caller() }} {%- endif -%} {% if not hide_description and field.description %}
{{ field.description | safe }}
{% endif %} {% if field.warning %} {%- call message_box('warning', fixed_width=true, classes='i-form-field-fixed-width form-field-warning') -%} {{ field.warning }} {%- endcall -%} {% endif %}
{%- endmacro %} {% macro form_row(field, widget_attrs={}, orientation='', allow_missing=false, skip_label=false, disabled=none, placeholder=false, classes='', hide_description=false) %} {% set widget_attrs = widget_attrs|default({}) %} {#- in case someone passed an Undefined object -#} {% if field or not allow_missing %}
{% if not skip_label %}
{%- if field.widget.input_type != 'checkbox' and (not field.widget.input_type or not placeholder) -%} {{ field.label() }} {%- endif -%} {%- if field.flags.required %}*{% endif -%}
{% endif %} {% set widget_attrs = dict(widget_attrs, placeholder=(field.label.text if placeholder else widget_attrs.get('placeholder', ''))) %} {% set classes = 'form-field %s' | format(classes) %} {%- if caller is defined -%} {% set caller_ = caller %} {% call form_field(field, classes, widget_attrs, disabled=disabled, hide_description=hide_description) -%} {{ caller_() }} {%- endcall %} {%- else -%} {{ form_field(field, classes, widget_attrs, disabled=disabled, hide_description=hide_description) }} {%- endif -%}
{% endif %} {%- endmacro %} {% macro form_rows(form, fields=none, skip=(), orientation='', skip_labels=false, widget_attrs={}, disable=(), placeholder=false) %} {% for field in _iter_form_fields(form, fields=fields, skip=skip) %} {{ form_row(field, widget_attrs.get(field.short_name, {}), orientation, skip_label=skip_labels, disabled=(true if field.short_name in disable else none), placeholder=placeholder) }} {% endfor %} {% endmacro %} {# `form` and `i_form` args are there in case we need them in the future #} {% macro form_footer(form, i_form=true, skip_label=false, align_right=false, classes='') -%} {% if caller is defined %} {% endif %}
{% endmacro %} {% macro form_fieldset(legend, description=none, disabled=false, render_as_fieldset=true, id=none, collapsible=false, initially_collapsed=true) %} {% if not render_as_fieldset %} {# This is sugar for cases where you sometimes want the fieldset to show up as a fieldset and sometimes just want the contents. The most common use case for this is a form which has either a single fieldset or multiple fieldsets depending on the user's privileges. In this case it often looks better not to show the single fieldset as an actual fieldset. Using `render_as_fieldset` keep the code using this macro clean as it won't need extra conditions/macros/blocks to show the same content either inside or outside this fieldset. #} {{ caller() }} {% else %}
{{ legend }} {% if collapsible -%}
{%- endif %}
{% if description %}

{{ description }}

{% endif %} {{ caller() }}
{% endif %} {% endmacro %} {# Renders a form with the most common default markup #} {% macro simple_form(form, fields=none, submit=none, back=none, back_url=none, back_button=true, disabled_until_change=true, disabled_fields=(), form_header_kwargs={}, skip_labels=false, save_reminder=false, footer_align_right=false, disable_if_locked=true, message=none) %} {% set submit = submit or _('Save') %} {% set back = back or _('Back') %} {{ form_header(form, disable_if_locked=disable_if_locked, **form_header_kwargs) }} {% if message %} {{ message_box('warning', message=message, icon=true) }} {% endif %} {% if caller is defined %} {{ caller() }} {% else %} {{ form_rows(form, fields=fields, disable=disabled_fields, skip_labels=skip_labels) }} {% endif %} {% call form_footer(form, skip_label=skip_labels, align_right=footer_align_right) %} {% if back_button %} {% if back_url %} {{ back }} {% else %} {% endif %} {% endif %} {% endcall %} {% endmacro %}