{%- macro extra_field(content, index=0, data={}, errors={}, name_template='extras__{index}__') -%} {%- set prefix = name_template.format(index=index) -%} {%- set id = 'field-extras-{}'.format(index+1) -%} {%- set error_list = errors[prefix~'key'] or errors[prefix~'value'] -%} {# control-custom class is is used by custom-fields module #}
{{ _input(name=prefix~'key', value=data.key | empty_and_escape, id=id~"-key", errors=error_list, prefix=_("Key"), **kwargs) }}
{% if data.key or data.value or error_list %} {% endif %} {{ _input(name=prefix~'value', value=data.value | empty_and_escape, id=id~"-value", errors=error_list, prefix=_("Value"), **kwargs) }}
{{ content }} {{ ui.field_errors(error_list) if error_list }}
{%- endmacro %} {%- macro extra_fields_collection(extras=[], errors={}, limit=3) -%}
{% for extra in extras %} {{ ui.extra_field(index=loop.index0, data=extra, errors=errors) }} {% endfor %} {# Add a max of 3 empty columns #} {% set total_extras = extras|count %} {% set empty_extras = (limit or 3) - total_extras %} {% if empty_extras <= 0 %}{% set empty_extras = 1 %}{% endif %} {% for extra in range(total_extras, total_extras + empty_extras) %} {{ ui.extra_field(index=loop.index0 + (extras|count), data=extra, errors=errors) }} {% endfor %}
{%- endmacro %} {%- macro field_errors(errors) -%}
{{ errors | join (", ") }}
{%- 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 input(content, name, id, label, value, required, placeholder, type, icon, errors=[], group_class="form-group") -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {%- set aria_attrs = kwargs.setdefault("aria", {}) -%} {%- if errors %}{%- do aria_attrs.setdefault("invalid", "true") -%}{%- endif -%}
{%- if label -%} {%- endif %}
{%- if icon -%} {%- endif %} {{ _input(name=name, value=value, placeholder=placeholder, type=type, id=field_id, errors=errors, required=required, **kwargs) }}
{{ content }} {{ ui.field_errors(errors) if errors }}
{%- endmacro %} {%- macro form_annotation() -%}

* {{ _("Required field") }}

{%- endmacro %} {%- macro field_info(content, icon="info-circle") -%}
{{- ui.icon("info-circle") if icon }} {{ content -}}
{%- endmacro %} {%- macro checkbox(content, name, id, checked, label, required, placeholder, type="checkbox", value="on", errors=[], group_class="form-group form-check") -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {%- set aria_attrs = kwargs.setdefault("aria", {}) -%} {%- if errors %}{%- do aria_attrs.setdefault("invalid", "true") -%}{%- endif -%} {%- set attrs = kwargs.setdefault("attrs", {}) -%} {%- do attrs.setdefault("class", "form-check-input") -%} {%- if checked -%}{%- do attrs.update({"checked": true}) -%}{%- endif %}
{{ _input(name=name, value=value, placeholder=placeholder, type=type, id=field_id, errors=errors, required=required, **kwargs) }} {%- if label -%} {%- endif %} {{ content }} {{ ui.field_errors(errors) if errors }}
{%- endmacro %} {%- macro _input(name, value, type, id, errors, placeholder, required, prefix, suffix, input_class="form-control") -%} {%- set input -%} {%- endset -%} {%- if prefix or suffix -%}
{%- if prefix -%}{{ prefix }}{%- endif %} {{ input }} {%- if suffix -%}{{ suffix }}{%- endif %}
{%- else -%} {{ input }} {%- endif -%} {%- endmacro %} {%- macro markdown_popover(id, title=_("Markdown quick reference")) -%} {%- call ui.util.call(ui.popover, title=title, id=id, **kwargs) -%} {%- 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=[], group_class="form-group control-full") -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%} {% set popover_id = ui.util.id() %} {{ ui.markdown_popover(id=popover_id) }} {%- set aria_attrs = kwargs.setdefault("aria", {}) -%} {%- if errors %}{%- do aria_attrs.setdefault("invalid", "true") -%}{%- endif -%}
{%- if label -%} {%- endif %}
{{ content }} {% trans trigger=ui.popover_handle(_("markdown formatting"), id=popover_id) %}you can use {{ trigger }} here{% endtrans %}
{{ ui.field_errors(errors) if errors }}
{%- 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 %} {%- do kwargs.setdefault("input_class", "form-range") -%} {{ 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 %} {%- elif option is mapping -%} {% set value = option.value %} {% set text = option.text or option.value %} {%- else -%} {% set value, text = option %} {%- 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=[], group_class="form-group") -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%}
{%- if label -%} {%- endif %} {{ nested_content }} {{ ui.field_errors(errors) if errors }}
{%- endmacro %} {%- macro select_option(content, value, selected) -%} {%- endmacro %} {%- macro submit(content, value, name) -%} {%- set attrs = kwargs.setdefault("attrs", {}) -%} {%- if value -%}{%- do attrs.update({"value": value}) -%}{%- endif %} {%- if name -%}{%- do attrs.update({"name": name}) -%}{%- endif %} {{- ui.button(content, type="submit", **kwargs) }} {%- endmacro %} {%- macro textarea(content, name, id, label, value, placeholder, required, errors=[], group_class="form-group control-full") -%} {%- set field_id = id or (name and "field-" ~ name) or (label and ui.util.id()) or "" -%}
{%- if label -%} {%- endif %}
{{ content }}
{{ ui.field_errors(errors) if errors }}
{%- endmacro %} {%- macro fieldset(content, legend) -%}
{%- if legend -%} {{ legend }} {%- endif %} {{ content }}
{%- endmacro %} {% macro image_upload() %} {{ _image_upload(*varargs, **kwargs) }} {%- endmacro -%} {% macro _image_upload(data, errors, field_url='image_url', field_upload='image_upload', field_clear='clear_upload', is_url=false, is_upload=false, is_upload_enabled=false, placeholder=false, url_label='', upload_label='', field_name='image_url') %} {% set placeholder = placeholder if placeholder else _('http://example.com/my-image.jpg') %} {% set url_label = url_label or _('Image URL') %} {% set upload_label = upload_label or _('Image') %} {% set previous_upload = data['previous_upload'] %} {% if field_url == 'url' and field_upload == 'upload' %} {# backwards compatibility for old resource forms that still call the `forms.image_upload()` macro, eg ckanext-scheming #} {% snippet 'package/snippets/resource_upload_field.html', data=data, errors=errors, is_url=is_url, is_upload=is_upload, is_upload_enabled=is_upload_enabled, url_label=url_label, upload_label=upload_label, placeholder=placeholder %} {% else %} {% if is_upload_enabled %}
{% endif %} {{ ui.input(name=field_url, label=url_label, id='field-image-url', type='url', placeholder=placeholder, value=data.get(field_url), errors=errors.get(field_url)) }} {% if is_upload_enabled %} {{ ui.input(name=field_upload, label=upload_label, id='field-image-upload', type='file') }} {{ ui.checkbox(name=field_clear, label=_('Clear Upload'), id='field-clear-upload', value='true') if is_upload }} {% endif %} {% if is_upload_enabled %}
{% endif %} {% endif %} {% endmacro %}