Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{#
Adds a block of custom form fields.
extras - The fields to add.
errors - A dict of errors for the fields.
limit - The total number of fields that should be output.
Example:
{% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
#}
{% import "macros/form.html" as form %}
<div data-module="custom-fields">
{% set custom_extras = ['licenseAttributionByText', 'temporal_start', 'temporal_end', 'issued', 'spatial_uri', 'groups'] %}
{% for extra in extras %}
{% if extra.key not in custom_extras %}
{% set prefix = 'extras__%d__' % (loop.index0 + (custom_extras|count)) %}
{{ form.custom(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % loop.index0,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endif %}
{% endfor %}
{# Add a max of 3 empty columns #}
{% set total_extras = data.extras|count %}
{% if total_extras <= (custom_extras|count) %}{% set total_extras = (custom_extras|count) %}{% endif %}
{% 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) %}
{% set index = loop.index0 + total_extras %}
{% set prefix = 'extras__%d__' % index %}
{{ form.custom(
names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
id='field-extras-%d' % index,
label=_('Custom Field'),
values=(extra.key, extra.value, extra.deleted),
error=errors[prefix ~ 'key'] or errors[prefix ~ 'value']
) }}
{% endfor %}
</div>