CASE: use persisted to hide parts of a loop

There might be some cases into where your fori-loop creates a whole range of inputs that need to be done, like below:

If you are like me, you’ll find the extra loop with all of its fields a little bit too much. I want to make the template a little less busy, and put extra emphasis that the first input is always needed to be filled in too.

By using the persisted method, I could make my template that way, that only the first field is visible. And only when information is filled in there, will it show all other fields, like this:

If nothing is filled, you’ll only see this:

As you can see, only one field is shown, and as a user you have no other option to fill it in.

You can make this work by using a persisted statement for all other fields, like this:

{% stripnewlines %}
| Name
| 
|
{% newline %}
|----20%----
|----20%----
|-----------{% ic %}#{% endic %}{% nic %}+{% endnic %}
{% fori comp in custom.companies %}
  {% newline %}
  | {% input comp.name %}
  {% if comp.persisted %} {% comment %}all other fields will be shown depending on which the loop "exists" or not, and that is defined in the first inpit{% endcomment %}
    {% newline %}
    |
    | VAT number
    | {% input comp.vat_nbr placeholder:"VAT nbr." %}
    {% newline %}
    | 
    | Street
    | {% input comp.street placeholder:"Street" %}
    {% newline %}
    | 
    | Number
    | {% input comp.nbr placeholder:"Number" %}
    {% newline %}
    | 
    | Postal code
    | {% input comp.postal_code placeholder:"Postal code" %}  
    {% newline %}
    |
    | City
    | {% input comp.city placeholder:"City" %}
    {% newline %}
    |
    | Country
    | {% input comp.country placeholder:"Country" %}
  {% endif %}
{% endfori %}
{% endstripnewlines %}

Actually, the persisted reads the same as if the loop exists or not. There are other ways to do this as well (checking on the input of the first object to see if it’s empty), but this is shorter though

Here’s another case as well: