From 59b181411c2eadc47aa3c15584f4b60714261957 Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Mon, 3 Jul 2023 14:06:05 +0200
Subject: [PATCH] Calculate length of custom dataset extras instead using
 harcoded value

---
 .../templates/organization/snippets/organization_form.html | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/ckanext/odsh/templates/organization/snippets/organization_form.html b/ckanext/odsh/templates/organization/snippets/organization_form.html
index a3cd0db7..a14c1221 100644
--- a/ckanext/odsh/templates/organization/snippets/organization_form.html
+++ b/ckanext/odsh/templates/organization/snippets/organization_form.html
@@ -47,8 +47,9 @@
     {{ form.input_address('gnd','GND URI', value=extras.gnd, index=6, placeholder='https://d-nb.info/gnd/1136109587', type='text', attrs={}) }}
 
     {% for extra in data.extras %}
-      {% if extra.key not in ['person','street','location','telephone','mail','web','gnd'] %}
-        {% set prefix = 'extras__%d__' % (loop.index0 + 7) %}
+      {% set custom_extras = ['person','street','location','telephone','mail','web','gnd'] %}
+      {% 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.index,
@@ -65,7 +66,7 @@
     {% if empty_extras <= 0 %}{% set empty_extras = 1 %}{% endif %}
   
     {% for extra in range(total_extras, total_extras + empty_extras) %}
-      {% set index = loop.index0 + (data.extras|count) + 7 %}
+      {% set index = loop.index0 + (data.extras|count) + (custom_extras|count) %}
       {% set prefix = 'extras__%d__' % index %}
       {{ form.custom(
         names=(prefix ~ 'key', prefix ~ 'value', prefix ~ 'deleted'),
-- 
GitLab