Skip to content
Snippets Groups Projects
Commit 9d9fecfe authored by Thorge Petersen's avatar Thorge Petersen
Browse files

Add package custom fields

parent 6cf88b4f
No related branches found
No related tags found
No related merge requests found
......@@ -15,4 +15,10 @@
{{ form.input(field, label=_('Is replaced by'), placeholder=_('https://'), value=value, error=error,
classes=['control-full']) }}
{% block package_metadata_fields_custom %}
{% block custom_fields %}
{% snippet 'snippets/custom_form_fields.html', extras=data.extras, errors=errors, limit=3 %}
{% endblock %}
{% endblock %}
{% endblock %}
\ No newline at end of file
{#
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>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment