{% set minItems = schema.get('minItems', 0) %}
{% set maxItems = schema.get('maxItems', None) %}
{% if data is not none %}
{% set numItems = (data | length) %}
{% else %}
{% set numItems = 0 %}
{% endif %}
{% if schema.style == "table" %}
{% if schema['items']['type'] == 'object' %}
{% set item_property_names = schema["items"].properties.keys() %}
{% set property_order = schema.get('items', {}).get('propertyOrder', []) %}
{% for property_name in property_order %}
{% if property_name in item_property_names %}
{% if data is not none %}
{% for item in data %}
{% set name = "item" %}
{% set schema = schema['items'] %}
{% set id_prefix = id_prefix + '_{}_'.format(loop.index0) %}
{% set data = item %}
{% for property_name in property_order %}
{% if property_name in item_property_names %}
{% set name = property_name %}
{% set schema = schema.properties[property_name] %}
{% set id_prefix = id_prefix + '_' + name + '_' %}
{% if data is not none and property_name in data %}
{% set data = data[property_name] %}
{% else %}
{% set data = none %}
{% endif %}
{% include "objects/forms/form_table_any.html" %}
{% endif %}
{% endfor %}
{% for property_name in item_property_names %}
{% if property_name not in property_order %}
{% set name = property_name %}
{% set schema = schema.properties[property_name] %}
{% set id_prefix = id_prefix + '_' + name + '_' %}
{% if data is not none and property_name in data %}
{% set data = data[property_name] %}
{% else %}
{% set data = none %}
{% endif %}
{% include "objects/forms/form_table_any.html" %}
{% endfor %}
{% if maxItems is none or numItems < maxItems %}
{% else %}
{% endif %}
{% elif schema['items']['type'] == 'array' %}
{% set max_used_fields = 0 %}
{% if data is not none %}
{% set max_used_fields = [0] %}
{% for item in data %}
{% if (item | length) > max_used_fields[-1] %}
{% set tmp = max_used_fields.append(item | length) %}
{% endif %}
{% endfor %}
{% set max_used_fields = max_used_fields [-1] %}
{% for i in range(max_used_fields) %}
Field {{ (i+1) }}
{% endfor %}
{% if (data | length) > 0 and max_used_fields > schema["items"].get("minItems", 1) %}
{% else %}
{% endif %}
{% if (data | length) > 0 and ("maxItems" not in schema["items"] or max_used_fields < schema["items"]["maxItems"]) %}
{% else %}
{% endif %}
{% for item in data %}
{% set item_index = loop.index0 %}
{% for field in item %}
{% set name = "field_".format(loop.index0) %}
{% set schema = schema["items"]["items"] %}
{% set id_prefix = id_prefix + '_{}__{}_'.format(item_index, loop.index0) %}
{% set data = field %}
{% include "objects/forms/form_table_any.html" %}
{% endfor %}
{% if (item | length) < max_used_fields %}
{% for i in range((item | length), max_used_fields) %}
{% set name ="field_".format(loop.index0) %}
{% set schema = schema["items"]["items"] %}
{% set id_prefix = id_prefix + '_{}__{}_'.format(item_index, i) %}
{% set data = null %}
{% include "objects/forms/form_table_any.html" %}
{% endfor %}
{% if maxItems is none or numItems < maxItems %}
{% else %}
{% endif %}
{% endif %}
{% elif schema.style == "list" %}
{% set itemName = schema['items'].title %}
{% if data is not none %}
{% for item in data %}
{% set name = "item" %}
{% set schema = schema['items'] %}
{% set id_prefix = id_prefix + '_{}_'.format(loop.index0) %}
{% set data = item %}
{% if 'note' in schema['items'] %}
Note: {{ schema['items']['note'] }}
{% endif %}
{% if maxItems is none or numItems < maxItems %}
{% else %}
{% endif %}
{% else %}
{% set itemName = schema['items'].title %}
{% if data is not none %}
{% for item in data %}
{% set name = "item" %}
{% set schema = schema['items'] %}
{% set id_prefix = id_prefix + '_{}_'.format(loop.index0) %}
{% set data = item %}
{% if numItems > minItems %}
{% else %}
{% endif %}
{% include "objects/forms/form_any.html" %}
{% endfor %}
{% endif %}
{% if maxItems is none or numItems < maxItems %}
{% else %}
{% endif %}