@Alexander_Krause_US
Thank you for your question.
The purpose of .key is that each input element of fori loop has a unique key, which can be connected to variables related to that input element.
For example,
{% stripnewlines %}
{% fori item in custom.test %}
{% input item.car placeholder:"Car model" %}
{% if item.car.persisted %}
{% input custom.variable_price.[item.key] placeholder:"Car price" as:currency %}
{% input custom.variable_colour.[forloop.index] placeholder:"Car colour" %} {% newline %}
{% endif %}
{% endfori %}
{% endstripnewlines %}
Example of main input in fori loop and related variables:
1st item. Car A
custom.variable_price.test_1 1,000
custom.variable_colour. 1. red
2nd item Car B
custom.variable_price.test_2 2,000
custom.variable_colour.2 green
3rd item. Car C
custom.variable_price.test_3 3,000
custom.variable_colour.3 blue
Let’s say, user deletes 2nd item in the loop - Car B.
Variables & results will be:
1st item Car A
custom.variable_price.test_1 1,000
custom.variable_colour. 1. red
2nd item Car C
custom.variable_price.test_3 3,000
custom.variable_colour.2 green
As a result 3rd item Car C, become now 2nd item in the loop.
Car C had related price 3,000 & colour blue.
Related price 3,000 was connected by using .key - it is displayed correctly.
Related colour blue was connected by using forloop.index number, after deletion displayed colour is green - not correct, should be blue . The reason is item number in the loop has changed.
To sum up, .key and forloop.index can be used to connect variables to for loop input item.
Due to above reason, if the sequence number of element can change in a loop/array - we recommend to avoid using forloop.index in connected variables names.
Please let me know if you have any further questions regarding .key and forloop.index usage.
Thanks.
Jelena