{% extends "look-and-feel/layouts/question.html" %} {% from "look-and-feel/components/fields.njk" import formSection, errorClass, errorsFor %} {% from "look-and-feel/components/header.njk" import header %} {% set defaultContent = { addAnotherLink: pageContent.addAnotherLink if pageContent.addAnotherLink else 'Add another item', itemLabel: pageContent.itemLabel if pageContent.itemLabel else 'item', noItemsMessage: pageContent.noItemsMessage if pageContent.noItemsMessage else 'No items added yet', itemsListLabel: pageContent.itemsListLabel if pageContent.itemsListLabel else 'Items', hideItemsListLabel: pageContent.hideItemsListLabel if pageContent.hideItemsListLabel else false, editItemLabel: pageContent.editItemLabel if pageContent.editItemLabel else 'Add another item' } %} {% block fields %} {% if isListMode %} {% block listItems %} {% call formSection() %} {% if not defaultContent.hideItemsListLabel %} {{ header(defaultContent.itemsListLabel, size='medium') }} {% endif %}
{% for fieldName, item in fields.items.fields %} {% call addAnotherItem(item, deleteUrl(loop.index0), editUrl(loop.index0), loop.index) %} {% block item %}{{ item.value }}{% endblock %} {% endcall %} {% else %} {% call addAnotherItem(noItems=true) %} {% block noItems %} {{ defaultContent.noItemsMessage }} {% endblock %} {% endcall %} {% endfor %}
{% endcall %} {% call formSection() %} {{ defaultContent.addAnotherLink }} {% endcall %} {% endblock %} {% endif %} {% if isEditMode %} {% block editItem %}

This is a placeholder block.

Replace it with form controls to edit the item, e.g.

    {% raw %}
    {% block editItem %}
      {{ textbox(this.fields.item, 'Item label') }}
    {% endblock %}
    {% endraw %}
    
{% endblock %} {% endif %} {% endblock %} {# Macro specific to this layout #} {% macro addAnotherItem(field, deleteUrl, editUrl, itemNumber, noItems=false) %}
{% if field %} {{ safeId(field.id) }} {% endif %}
{{ errorsFor(field) }} {{ caller() }}
{% if deleteUrl or editUrl %}
{% if editUrl %} Edit{{ defaultContent.itemLabel }} {{ itemNumber }} {% endif %} {% if deleteUrl %} Delete{{ defaultContent.itemLabel }} {{ itemNumber }} {% endif %}
{% endif %} {% endmacro %}