{% from 'macros/form.html' import image_upload as _image_upload %} {%- macro checkbox(content, checked, value="on", type="checkbox") -%} {%- if checked -%} {%- do kwargs.setdefault("attrs", {}).setdefault("checked", true) -%} {%- endif %} {{ ui.input(content, value=value or "on", type=type, **kwargs) }} {%- endmacro %} {%- macro extra_field(index, data={}, errors={}, name_template='extras__{index}__') -%} {%- set prefix = name_template.format(index=index) -%}
{{ _('Custom Field') }} {{ ui.input(name=prefix ~ "key", label=_("Key"), value=data.key, errors=errors[prefix~"key"]) }} {{ ui.input(name=prefix ~ "value", label=_("Value"), value=data.value, errors=errors[prefix~"value"]) }} {{ ui.button(_("Remove"), style="danger", attrs={"onclick": "this.closest('fieldset').remove()"}) }}
{%- endmacro %} {%- macro extra_fields_collection(extras=[], errors={}, limit=3) -%}
{%- for extra in extras -%} {{ ui.extra_field(index=loop.index0, data=extra, errors=errors) }} {%- endfor %} {%- set num_extras = extras|count %} {%- set max_extras = [limit - num_extras, 1]|max + num_extras %} {%- for index in range(num_extras, max_extras) -%} {{ ui.extra_field(index=index) }} {%- endfor %} {{ ui.button(_("Add"), data={"index": max_extras}, attrs={"onclick": " const tpl = document.getElementById('custom-field-template').content.cloneNode(true); tpl.querySelectorAll('input').forEach(el => { el.name = el.name.replace('TPL', this.dataset.index); el.id = el.id.replace('TPL', this.dataset.index); }); tpl.querySelectorAll('label').forEach(el => { el.setAttribute('for', el.getAttribute('for').replace('TPL', this.dataset.index)); }); ++this.dataset.index; this.parentNode.insertBefore(tpl, this); "}, **kwargs) }}
{%- endmacro %} {%- macro field_errors(errors) -%} {%- if errors -%}
{%- for error in errors -%} {{ error }}{% if not loop.last %}
{% endif %} {%- endfor %}
{%- endif %} {%- endmacro %} {%- macro file_input(content, accept, capture, multiple) -%} {%- if multiple -%} {%- do kwargs.setdefault("attrs", {}).setdefault("multiple", true) -%} {%- endif %} {%- if accept -%} {%- do kwargs.setdefault("attrs", {}).setdefault("accept", accept) -%} {%- endif %} {%- if capture -%} {%- do kwargs.setdefault("attrs", {}).setdefault("capture", capture) -%} {%- endif %} {{ ui.input(content, type="file", **kwargs) }} {%- endmacro %} {%- macro form(content, method, action, enctype, include_csrf=true) -%} {{ ui.form_start(method, action, enctype, **kwargs) }} {{ h.csrf_input() if include_csrf and method and method|upper != "GET" }} {{ content }} {{ ui.form_end() }} {%- endmacro %} {%- macro form_actions(content) -%} {{ content }} {%- endmacro %} {%- macro form_end(content) -%} {%- do kwargs -%} {{ content }} {%- endmacro %} {%- macro form_errors(errors) -%} {% if errors %}

{{ _('The form contains invalid entries:') }}

{% endif %} {%- endmacro %} {%- macro form_start(method, action, enctype) -%}
{%- endmacro %} {%- macro hidden_input(name, value) -%} {%- endmacro %} {%- macro form_annotation() -%} {%- endmacro %} {%- macro field_info(content) -%}
{{ content }}
{%- endmacro %} {%- macro input(content, name, id, label, value, required, placeholder, type, errors=[]) -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {%- set help_id = ui.util.id() if content -%} {%- set aria_attrs = kwargs.setdefault("aria", {}) -%} {%- if content %}{%- do aria_attrs.setdefault("describedby", help_id) -%}{%- endif -%} {%- if errors %}{%- do aria_attrs.setdefault("invalid", "true") -%}{%- endif -%}
{%- if label -%} {%- endif %} {{ ui.field_info(content, attrs={"id": help_id}) if content }} {%- if errors %}
{{ ui.field_errors(errors) }}
{%- endif %}
{%- endmacro %} {%- macro markdown_popover(id, title=_("Markdown formatting")) -%} {%- call ui.util.call(ui.popover, title=title, id=id) -%} {%- if content -%} {{ content }} {%- else -%} {%- trans -%}

__Bold text__ or _italic text_

# title
## secondary title
### etc

* list
* of
* items

http://auto.link.ed/

Full markdown syntax

Please note: HTML tags are stripped out for security reasons

{%- endtrans %} {%- endif %} {%- endcall -%} {%- endmacro %} {%- macro markdown(content, name, id, label, value, placeholder, required, errors=[]) -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {%- set help_id = ui.util.id() if content -%} {% set popover_id = ui.util.id() %} {{ ui.markdown_popover(id=popover_id) }}
{%- if label -%} {%- endif %} {{ ui.field_info(content, attrs={"id": help_id}) if content }} {%- call ui.util.call(ui.field_info) -%} You can use {{ ui.popover_handle(_("Markdown formatting"), id=popover_id) }} here {%- endcall %} {%- if errors %}
{{ ui.field_errors(errors) }}
{%- endif %}
{%- endmacro %} {%- macro radio(content, checked, value="on") -%} {{ ui.checkbox(content, checked=checked, value=value or "on", type="radio", **kwargs) }} {%- endmacro %} {%- macro range_input(content, min_value, max_value, step) -%} {%- if min_value is defined -%} {%- do kwargs.setdefault("attrs", {}).setdefault("min", min_value) -%} {%- endif %} {%- if max_value is defined -%} {%- do kwargs.setdefault("attrs", {}).setdefault("max", max_value) -%} {%- endif %} {%- if step is defined -%} {%- do kwargs.setdefault("attrs", {}).setdefault("step", step) -%} {%- endif %} {{ ui.input(content, type="range", **kwargs) }} {%- endmacro %} {%- macro select(content, selected, options) -%} {%- set selected_values = selected if selected is not string and selected is iterable else [selected or ""] %} {%- call ui.util.call(ui.select_box, content, selected=selected, options=options or [], **kwargs) -%} {%- for option in (options or []) %} {%- if option is string %} {% set value, text = option, option %} {%- else -%} {% set value = option.value %} {% set text = option.text or option.value %} {%- endif %} {{ ui.select_option(text, value, selected=value in selected_values) }} {%- endfor %} {%- endcall %} {%- endmacro %} {%- macro select_box(content, nested_content, name, id, label, multiple, required, autocomplete, errors=[]) -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {%- set help_id = ui.util.id() if nested_content -%}
{%- if label -%} {%- endif %} {{ ui.field_info(nested_content, attrs={"id": help_id}) if nested_content }} {%- if errors %}
{{ ui.field_errors(errors) }}
{%- endif %}
{%- endmacro %} {%- macro select_option(content, value, selected) -%} {%- endmacro %} {%- macro submit(content, value, name) -%} {%- do kwargs.setdefault("attrs", {}).update({"value": value, "name": name}) -%} {{ ui.button(content, type="submit", **kwargs) }} {%- endmacro %} {%- macro textarea(content, name, id, label, value, placeholder, required, errors=[]) -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {%- set help_id = ui.util.id() if content -%}
{%- if label -%} {%- endif %} {{ ui.field_info(content, attrs={"id": help_id}) if content }} {%- if errors %}
{{ ui.field_errors(errors) }}
{%- endif %}
{%- endmacro %} {% macro image_upload() %} {{ _image_upload(*varargs, **kwargs) }} {%- endmacro -%} {%- macro fieldset(content, legend) -%}
{%- if legend -%} {{ legend }} {%- endif %} {{ content }}
{%- endmacro %}