Have a question with regard to this code. It works (on the basis of a couple of questions, you can go from input to output with a minimum of code. Do you see problems with this approach (want to know this before I implement it accross different templates). Thanks!
{% comment %}Geef vragen in (evt dynamisch via result-tag{% endcomment %}
{% stripnewlines %}
{% assign
arr_Serie1_StandardTasks_Descriptions
=
"
Inboeken van de boekhoudkundige documenten.
|
Bijstand bij opmaak en indiening van de BTW -aangifte.
|
Voorbereiding en indiening van de aangifte bedrijfsvoorheffing.
|
Contacten met de bank.
|
Betaling van de leveranciersfacturen.
|
Betaling van de lonen.
|
Opvolging van openstaande klanten.
|
Opstellen van een maandelijkse of trimestriële rapportering en bespreking.
|
Opstellen van prognoses die maandelijks of trimestrieel worden aangepast."
| split:"|"
%}
{% endstripnewlines %}
{% comment %}Stel output op{% endcomment %}
{% stripnewlines %}
{% for task in arr_Serie1_StandardTasks_Descriptions %}
{% ic %}
{% newline %}
- {% input custom.arr_Serie1_StandardTasks_Checkbox[forloop.index0] as:boolean default:false %} {{arr_Serie1_StandardTasks_Descriptions[forloop.index0] | strip}}
{% endic %}
{% if custom.arr_Serie1_StandardTasks_Checkbox[forloop.index0] == 'true' %}
{% nic %}
{% newline %}- {{arr_Serie1_StandardTasks_Descriptions[forloop.index0] | strip}}
{% endnic %}
{% endif %}
{% endfor %}
{% endstripnewlines %}
@Bart_Verhaeghe, really like what you did there! Combine an array with a list of booleansâŠ
I wouldâve done this though :
{% assign arr_Serie1_StandardTasks_Descriptions = "Inboeken van de boekhoudkundige documenten.|Bijstand bij opmaak en indiening van de BTW -aangifte.|Voorbereiding en indiening van de aangifte bedrijfsvoorheffing.|Contacten met de bank.|Betaling van de leveranciersfacturen.|Betaling van de lonen.|Opvolging van openstaande klanten.|Opstellen van een maandelijkse of trimestriële rapportering en bespreking.|Opstellen van prognoses die maandelijks of trimestrieel worden aangepast." | split:"|" %}
So you didnât need to bother to strip the new lines and all, but other than that:
Also, another thing I learned, is to use a second array to use as an unique key.
Why? You donât want to find a type in your questions sometime in the future where you want to change that typo. When changing that typo, your âuniqueâ input object will disappear (because the name of that object changes).
See also:
Another related question though: Iâd like to compose the array with the unique keys on the basis of the original array âarr_Serie1_StandardTasks_Descriptionsâ.
So the array with should be something like âStandardTask_Opt0|StandardTask_Opt1|StandardTask_Opt2â with the number running from 0 to the size of the array âarr_Serie1_StandardTasks_Descriptionsâ. What would be the easiest way to achieve this?
You could create a second array based on the first: if you loop over that first array, and in each loop you create a variable where a fixed name is made, append it with a number and a â;â. That variable can then be used to create the second array.
But, the reason I donât post an example of this code, is because you can always screw up things if you add a new part into your first array. Itâll affect the second array and a key like âkey_5â (where this key was in the 5th loop for instance) can become âkey_6â all of a sudden, simply because you added a new part before the 5th part.
Thatâs why Iâd suggest doing it manually with some unique words and/or numbers for each part of your first array. Manually to do, I know, but it canât be done all automatically. Like your thinking though
The code can be written a little bit shorter.
Iâd do it like this:
{% comment %}Geef vragen in (evt dynamisch via result-tag{% endcomment %}
{% stripnewlines %}
{% assign
arr_Serie1_StandardTasks_Descriptions
= "
Inboeken van de boekhoudkundige documenten.|
Bijstand bij opmaak en indiening van de BTW -aangifte.|
Voorbereiding en indiening van de aangifte bedrijfsvoorheffing.|
Contacten met de bank.|
Betaling van de leveranciersfacturen.|
Betaling van de lonen.|
Opvolging van openstaande klanten.|
Opstellen van een maandelijkse of trimestriële rapportering en bespreking.|
Opstellen van prognoses die maandelijks of trimestrieel worden aangepast." | split:"|"
%}
{% endstripnewlines %}
{% comment %}Stel output op{% endcomment %}
{% stripnewlines %}
{% for task in arr_Serie1_StandardTasks_Descriptions %}
{% newline %}
{% ifi custom.arr_Serie1_StandardTasks_Checkbox[forloop.index0] == 'true' %}{% nic %}- {% endnic %}{% input custom.arr_Serie1_StandardTasks_Checkbox[forloop.index0] as:boolean default:false %} {{arr_Serie1_StandardTasks_Descriptions[forloop.index0] | strip}}
{% endifi %}
{% endfor %}
{% endstripnewlines %}
Escpecially the last part with the ifi is interesting
Just tested this and the Svenâs remarks are still valid (eg if you mark the first three options to âyesâ, and then âdeleteâ the second option afterwards, the booleans âchangeâ).