CASE: create dropdown and display info chosen element

Let us built a case in which we want to create a dropdown lit of all shareholders we hve. When selected one, we want to display its relevant info from that selected shareholder:

Beneath is how we can approach such case:


{% comment %}all info regarding shareholders are in the drop period.shareholders{% endcomment %}
{% assign shareholders = period.shareholders %}

{% comment %}create variable of all the names of each shareholder, splitted by a "|". This will be used later on as the options for our dropdown. Linked to that, we use the unique "ID" each person has for the option values too{% endcomment %}
{% assign names = "" %}
{% assign values = "" %}
{% for person in shareholders %}
  {% comment %}it is the db var "represented_by_name" that decides if a person is legal or not - needed for default dropdown LEGAL OR NOT{% endcomment %}
  {% assign default_type = "" %}
  {% if person.custom.represented_by_name != blank %}
    {% assign default_type = "legal" %}
  {% else %}
    {% assign default_type = "nature" %}
  {% endif %}
  {% comment %}look at the dropdown to check whether someone is LEGAL or not{% endcomment %}
  {% assign type = person.custom.type | default:default_type %} 
  {% comment %}create the needed arrays for select and option_values later on{% endcomment %}
  {% if type == "legal" %}
    {% assign names = names | append:person.name %} {% comment %}name of legal person is stored in db var .name{% endcomment %}
    {% assign values = values | append:person.id %} {% comment %}unique for every person{% endcomment %}
  {% else %}
    {% assign names = names | append:person.custom.first_name | append:" " | append:person.custom.last_name %} {% comment %}name of non-legal person is stored in db var custom.first_name & custom.last_name{% endcomment %}
    {% assign values = values | append:person.id %} {% comment %}unique for every person{% endcomment %}
  {% endif %}
  {% unless forloop.last %} {% comment %}each value in the array needs to be split on "|" except for the last element (= loop) in the array{% endcomment %}
    {% assign names = names | append:"|" %}
    {% assign values = values | append:"|" %}
  {% endunless %}
{% endfor %}

{% comment %}create info text to chose the shareholder{% endcomment %}
{% ic %}{::infotext}
Choose shareholder: {% input custom.choosing.shareholders as:select options:names option_values:values %} 
{:/infotext}{% endic %}

{% comment %}
the select creates a dropdown, the options visualises the elements of the dropdown and the option_values is the actual value of each chosen element ==> the ID of a person!
This means that the value of custom.choosing.shareholders is the ID and not the name! 
{% endcomment %}

* * *

{% comment %}let us loop over the complete period. shareholders drop and display the person that has the same ID as the chosen person from the dropdown, and display the info like name, VAT nbr, ...{% endcomment %}

{% stripnewlines %}
| Name shareholder
| VAT nbr
| Amount of shares
{% newline %}
|----25%----
|----25%----
|-----------{% ic %}+{% endic %}{% nic %}#{% endnic %}
{% for person in period.shareholders %}
  {% if person.id == custom.choosing.shareholders %}
    {% comment %}it is the db var "represented_by_name" that decides if a person is legal or not - needed for default dropdown LEGAL OR NOT{% endcomment %}
    {% assign default_type = "" %}
    {% if person.custom.represented_by_name != blank %}
      {% assign default_type = "legal" %}
    {% else %}
      {% assign default_type = "nature" %}
    {% endif %}
    {% comment %}look at the dropdown to check whether someone is LEGAL or not{% endcomment %}
    {% assign type = person.custom.type | default:default_type %}   
    
      {% newline %}
      | {% if type == "legal" %}
          {{ person.name }}
        {% else %}
          {{ person.custom.first_name }} {{ person.custom.last_name }}
        {% endif %}
      | {{ person.custom.vat_identifier }}  
      | **{{ person.amount_of_shares | integer }}**
  {% endif %}
{% endfor %}
{% endstripnewlines %}

Hi @sven

I got to work with the case-code you posted earlier. In stead of amount of shares I’ve managed it to show the address of the shareholder. For the RPR I have not found a solution … yet. So when using the below mentioned code I encounter two problems:

  1. I select a shareholder but the legal form is shown as ‘15’:
    image

I know this refers to the legal form ‘BVBA’ but what part of the code do I need to adapt / correct in order for it to show the actual legal form and not the reference to the legal form?

  1. In my example there are two shareholders, a legal person and a natural person. When opening the dropdown, for some reason only the name of the legal person is shown in the dropdown-list. When selecting the ‘blank’-shareholder, an address is shown (coincidentally it’s the same address as the legal person which would be correct) but still not the name:

image

{% ic %}{::infotext}
Selecteer aandeelhouder: {% input custom.choosing.shareholders as:select options:names option_values:values %} 
{:/infotext}{% endic %}

{% comment %}
the select creates a dropdown, the options visualises the elements of the dropdown and the option_values is the actual value of each chosen element ==> the ID of a person! This means that the value of custom.choosing.shareholders is the ID and not the name! 
{% endcomment %}

{% stripnewlines %}
{% for person in period.shareholders %}
  {% if person.id == custom.choosing.shareholders %}
    {% comment %}it is the db var "represented_by_name" that decides if a person is legal or not - needed for default dropdown LEGAL OR NOT{% endcomment %}
    {% assign default_type = "" %}
    {% if person.custom.represented_by_name != blank %}
      {% assign default_type = "legal" %}
    {% else %}
      {% assign default_type = "nature" %}
    {% endif %}
    {% comment %}look at the dropdown to check whether someone is LEGAL or not{% endcomment %}
    {% assign type = person.custom.type | default:default_type %}   
        {% newline %}
      Naam: {% if type == "legal" %} {{ person.custom.company_form }} 
      {% comment %}display name of company form instead of the option value{% endcomment %}
{% assign type = person.custom.type | default:default_type %} 

{% case person.custom.company_form.string_value %}
{% when "001" %}
  {% assign name_company_form = "ECV" %}
{% when "002" %}
  {% assign name_company_form = "OFP" %}
{% when "006" %}
  {% assign name_company_form = "CVOA" %} 
{% when "008" %}
  {% assign name_company_form = "CVBA" %}  
{% when "011" %}
  {% assign name_company_form = "VOF" %}  
{% when "012" %}
  {% assign name_company_form = "GCV" %}  
{% when "013" %}
  {% assign name_company_form = "CVA" %}  
{% when "014" %}
  {% assign name_company_form = "NV" %} 
{% when "015" %}
  {% assign name_company_form = "BVBA" %}  
{% when "021" %}
  {% assign name_company_form = "OVZM" %} 
{% when "017" %}
  {% assign name_company_form = "VZW" %} 
{% when "027" %}
  {% assign name_company_form = "EV" %}   
{% when "018" %}
  {% assign name_company_form = "ION" %}
{% when "030" %}
  {% assign name_company_form = "BO" %}  
{% when "060" %}
  {% assign name_company_form = "EESV" %}
{% when "023" %}
  {% assign name_company_form = "BPV" %} 
{% when "023" %}
  {% assign name_company_form = "BPV" %} 
{% when "065" %}
  {% assign name_company_form = "EESV" %}
{% when "026" %}
  {% assign name_company_form = "PRIV ST" %}  
{% when "265" %}
  {% assign name_company_form = "EES" %}   
{% when "506" %}
  {% assign name_company_form = "CVOA SO" %}   
{% when "029" %}
  {% assign name_company_form = "SON" %}     
{% when "508" %}
  {% assign name_company_form = "CVBA SO" %}
{% when "511" %}
  {% assign name_company_form = "VOF SO" %}
{% when "512" %}
  {% assign name_company_form = "GCV SO" %} 
{% when "513" %}
  {% assign name_company_form = "CVA SO" %} 
{% when "121" %}
  {% assign name_company_form = "OVM" %}  
{% when "514" %}
  {% assign name_company_form = "NV SO" %}
{% when "125" %}
  {% assign name_company_form = "IVZW" %}
{% when "510" %}
  {% assign name_company_form = "BVBA SO" %} 
{% when "560" %}
  {% assign name_company_form = "ESV SO" %}  
{% endcase %}
      {{ person.name }} {% else %}{{ person.custom.first_name }} {{ person.custom.last_name }}{% endif %}<br>
      Adres: {{ person.address_1 }}, {{ person.address_2 }}<br>
      O.N.: {{ person.custom.vat_identifier }}<br>  
  {% endif %}
{% endfor %}
{% endstripnewlines %}

Hey @Francis,

Great to see you are picking this up :+1:

Regarding the problems:

  1. legal form shown as “15”

This is because the dropdown of the legal forms is linked to option_values, where the value of that is used in XBRL for the workflow of Annual Accounts.

For now (but we hope to get a better solution for this ofc) you have to re-create and assign the “option value” to a new variable, something like this:


{% case person.custom.company_form %}
      {% when 1 %}{% assign legal_type = 'SCE' %}
      {% when 2 %}{% assign legal_type = 'OFP' %}
      {% when 6 %}{% assign legal_type = 'CVOA' %}
      {% when 8 %}{% assign legal_type = 'CVBA' %}
      {% when 11 %}{% assign legal_type = 'VOF' %}
      {% when 12 %}{% assign legal_type = 'CV' %}
      {% when 13 %}{% assign legal_type = 'COMMVA' %}
      {% when 14 %}{% assign legal_type = 'NV' %}
      {% when 15 %}{% assign legal_type = 'BVBA' %}
      {% when 21 %}{% assign legal_type = 'OVM' %}
      {% when 17 %}{% assign legal_type = 'VZW' %}
      {% when 27 %}{% assign legal_type = 'SE' %}
      {% when 18 %}{% assign legal_type = 'ION' %}
      {% when 30 %}{% assign legal_type = 'Buitenlandse onderneming' %}
      {% when 60 %}{% assign legal_type = 'ESV' %}
      {% when 23 %}{% assign legal_type = 'Buitenlandse privaatrechtelijke vereniging met vestiging, agentschappen, kantoor of bijhuis in België' %}
      {% when 65 %}{% assign legal_type = 'EESV' %}
      {% when 26 %}{% assign legal_type = 'PRIV ST' %}
      {% when 265 %}{% assign legal_type = 'Europees economisch samenwerkingsverband zonder zetel met vestiging in België' %}
      {% when 506 %}{% assign legal_type = 'CVOA SO' %}
      {% when 29 %}{% assign legal_type = 'SON' %}
      {% when 508 %}{% assign legal_type = 'CVBA SO' %}
      {% when 511 %}{% assign legal_type = 'VOF SO' %}
      {% when 512 %}{% assign legal_type = 'GCV SO' %}
      {% when 513 %}{% assign legal_type = 'CVA SO' %}
      {% when 121 %}{% assign legal_type = 'Onderlinge verzekeringsmaatschappij, van publiek recht' %}
      {% when 514 %}{% assign legal_type = 'NV SO' %}
      {% when 125 %}{% assign legal_type = 'IVZW' %}
      {% when 510 %}{% assign legal_type = 'BVBA SO' %}
      {% when 560 %}{% assign legal_type = 'ESV SO' %}
    {% endcase %}

Above is part of the code we use in our legal templates.
So, we create a var legal_type back to its original value.

Quite the workaround, we know, but you can copy-paste above and put it in your forloop.

  1. empty name

Could you check if the name of the “non-legal” person is not saved in person.name instead?

What we actually do in such case (because the name of a person, whether legal or not, is actually synced to the database variable .name and we will take that value and split that up with this logic (just an example - this can not just be copy pasted without adjusting some things):

{% if type == "legal" %}
      {% assign current_secretaris = person.name %}
    {% else %}
      {% if person.custom.first_name == blank and person.custom.last_name == blank %}
        {% assign current_secretaris = person.name %}
      {% elsif person.custom.first_name == blank and person.custom.last_name != blank %}
        {% assign current_secretaris = current_secretaris | append:person_first_name | append:" " | append:person.custom.last_name %}
      {% elsif person.custom.first_name != blank and person.custom.last_name == blank %}
        {% assign current_secretaris = current_secretaris | append:person.custom.first_name | append:" " | append:lastname %}
      {% else %}
        {% assign current_secretaris = current_secretaris | append:person.custom.first_name | append:" " | append:person.custom.last_name %}
      {% endif %}
    {% endif %}   

What we do here, is assign the .name to a variable if it’s legal.
When it is a non-legal person, the value of the name is either saved in .name (when the data is synced) OR the name is entered in .custom.first_name and .custom.last_name when data is not synced but entered manually.

So this could be built in as well, as we do by the way in our legal text templates.

Hope this helps, if not, you know how to reach us