Actions

ExpressionScript examples/nl: Difference between revisions

From LimeSurvey Manual

m (FuzzyBot moved page Expression Manager examples/nl to ExpressionScript examples/nl without leaving a redirect: Part of translatable page "Expression Manager examples")
(Updating to match new version of source page)
Line 1: Line 1:
<languages />
<languages />
__TOC__
__TOC__


{{Note|'''Help door dit artikel uit te breiden''' door je eigen voorbeelden toe te voegen. Dit zal anderen helpen Expressiebeheer te gebruiken.}}
{{Note| '''Please help extending this article''' by adding your own examples. This will help others getting started using the Expression Manager.}}




=Structuur=
=Structure=




In het eerste deel van het artikel wordt beschreven waarvoor expressies gebruikt kunnen worden en waar je ze kunt vinden en hoe je ze kunt wijzigen. Het tweede deel bevat  voorbeelden van het gebruik van een expressie.
The first part of the article will describe what Expressions can be used for and where to find/add an Expression. The second part provides examples on how to use Expression.




= Categorieën van expressies =
=Categories of Expressions=




LimeSurvey gebruikt expressies voor:
LimeSurvey uses Expressions for the following purposes:
*[[Expression_Manager_examples/nl# Relevance |Relevantie]]
* [[Expression_Manager_examples#Relevance|Relevance]]
*[[Expression_Manager_examples/nl#Validation|Validatie]]
* [[Expression_Manager_examples#Validation|Validation]]
*[[Expression_Manager_examples/nl#Tekstuitvoer|Tekstuitvoer]]
* [[Expression_Manager_examples#Text output|Text output]]
*[[Expression_Manager_examples/nl#Antwoorden opslaan|Antwoorden opslaan]]  
* [[Expression_Manager_examples#Answers storing|Answers storing]]  




== Relevantie ==
==Relevance==




'''Doel: verbergen van vraaggroep/vraag'''
'''Purpose: Hiding question groups/questions'''


Relevantie bepaalt of een vraaggroep of vraag wordt getoond of verborgen. Als het resultaat van de expressie "waar" is (d.w.z. 1), wordt het element getoond. Anders (d.w.z. 0), zal het element verborgen zijn.
Relevance controls whether a question group or question is shown or hidden. If the result of the Expression is "true" (i.e. 1), the element will be shown. Otherwise (if the result of the Expression is "false" (i.e. 0)), the element will be hidden.


{|class="wikitable"
{|class="wikitable"
Line 42: Line 40:




==Validatie==
==Validation==




'''Doel: Valideren van invoer / acties op vragen / subvragen / antwoorden'''
'''Purpose: Validate input/actions on questions/subquestions/answers'''


Met validatie bedoelen we het controleren of de gebruikersinvoer als antwoord op een vraag geldig is of niet. Bij een resultaat "true" (1) van de expressie, wordt de class "good" gebruikt voor het element en het validatie-bericht. In het andere geval wordt de class "error" hierbij gebruikt. Je kunt de classes declareren in het bestand '''template.css'''.
Validation controls whether the respondent's input into a question or action is valid or not. If the result of the Expression is "true" (i.e. 1), the "good" class will be applied to the element and validation message. Otherwise, if the result of the Expression is "false" (i.e. 0)), the "error" class will be apllied to the element and validation message. You can declare a style for these classes in the '''template.css'''.


{|class="wikitable"
{|class="wikitable"
!Type!!Valideren!!Waar staat het!!Screenshot
!Type!!Validates!!Where to find!!Screenshot
|-
|-
|Vraag validatie||Vraag||Vraag aanmaken/aanpassen -> tab "Logica" -> "Vraag relevantievergelijking"||[[File:Question validation equation.png|30px]]
|Question Validation||question||Create/Edit question -> "Logic tab" -> "Question validation equation"||[[File:Question validation equation.png|30px]]
|-
|-
|Subvraag validatie||Subvragen||Vraag aanmaken/aanpassen -> tab "Logica" -> "Subvraag relevantievergelijking"||[[File:Subquestion validation screenshot.png|30px]] ‎
|Subquestion Validation||subquestions||Create/Edit question -> "Logic tab" -> "Subquestion validation equation"||[[File:Subquestion validation screenshot.png|30px]] ‎
|}
|}


==Tekstuitvoer==
==Text output==




'''Doel: (doe iets) en toon wat tekst'''
'''Purposes: (Do something) and write out some text'''


Een expressie kan worden gebruikt om tekst te tonen. Je kunt bijvoorbeeld iets testen en berekenen en de uitvoer specificeren afhankelijk van het resultaat van de test of berekening. Het kan ook worden gebruikt om de vraagtekst, antwoorden, vraagtypen, ... in een vraag toe te voegen die werd gebruikt voordat de uitdrukking wordt gebruikt. Tekstuitvoer kan overal worden gebruikt waar een tekst wordt getoond en kan alle soorten resultaten retourneren.
An Expression can be used to write out some text. For example, you can test or calculate something and specify the output depending on the result of the test or calculation. It can also be used to insert the question text, answers, question types, ... of a question used before the Expression is used. Text output can be used everywhere where a text is shown and can return every kind of results.


{|class="wikitable"
{|class="wikitable"
!Gebruik!!Beschrijving
!Use Case!!Description
|-
|-
|Klein maatwerk||Gebruik een tekst, bijv. "Dhr." of "Mevr." afhankelijk van het eerder gevraagde geslacht
|Micro tailoring||Adjust a text, e.g., write "Mr" or "Mrs" depending on a gender question asked before
|-
|-
|Berekening||Bereken een waarde en toon die, bijv. "Het inkomen van uw familie is xxx"
|Calculation||Calculate a value and write it out, e.g., "Your family income is xxx"
|-
|-
|Referentie||Gebruik een element, bijv. "Je naam is xxx. Hoe oud ben je?"
|Reference||Insert a text from an element, e.g., "Your name is xxx. How old are you?"
|}
|}




==Antwoorden opslaan==
==Answers storing==




'''Doel: (doe iets,) (toon wat tekst) en sla iets op in de database'''
'''Purposes: (Do something,) (write out some text) and store something in the database'''


Het [[Question type - Equation/nl|vraagtype vergelijking]] kan worden gebruikt om iets in de database op te slaan. Je kunt dit met een expressie doen, de vergelijkingsvraag (die lijkt op een [[Question type - Text display/nl|tekst scherm]]) weergeven en het resultaat van de expressie opslaan in de database. Het slaat het antwoord op in de tabel responses. Het resultaat kan vervolgens worden gebruikt binnen de statistiekfunctie, het kan ook worden geïmporteerd in een van de formaten die worden geboden bij de exportfunctie van LimeSurvey.
[[Question type - Equation|The Equation Question Type]] can be used to store something in the database. You can do something with an Expression, show the Equation question (which is similar to a [[Question type - Text display|text display]]) and store the result of the Expression in the database. It stores the answer into the responses table. Then, the result can be used within the statistics feature or it can also be imported into one of the formats provided by the LimeSurvey export functionality.


=Voorbeelden van een expressie=
=Examples for Expressions=




==Voeg een antwoord van een vorige vraag in==
==Insert an answer from a previous question==




{| class="wikitable"
{| class="wikitable"
|Doel||Gebruik een eerder gegeven antwoord in de vraag
|Purpose||Insert an answer from a previous question
|-
|-
|Type||Referentie
|Type||Reference
|-
|-
|Voorbeeld||Vraag 1 (vraagcode "Q00"): What city do you live in? <br /> Vraag 2 (vraagcode "Q01"): How long have you lived in CITY? <br /> Bedoeling: Het antwoord op vraag 1 gebruiken in vraag 2 in plaats van CITY.
|Example||Question one (question code "Q00"): What city do you live in? <br /> Question two (question code "Q01") How long have you lived in CITY? <br /> To do: The answer from question one should be used instead of "CITY" from the second question.
|-
|-
|Expressie||{QOO}
|Expression||{QOO}
|-
|-
|Beschrijving|| Het in Q00 gegeven antwoord vervangt het Q00-veld in vraag 2.
|Description|| The answer provided in Q00 replaces the Q00 field from the second question
|-
|-
|Stappen||Maak of wijzig vraag 2<br /> Voer "How long have you lived in {QOO} (years)?" in bij het invoerveld
|Steps||Create/Edit question two <br /> Insert "How long have you lived in {QOO} (years)?" into the question text field
|-
|-
|colspan="2" align="center"|[[File:Simple expression city name.png]]
|colspan="2" align="center"|[[File:Simple expression city name.png]]
|}
|}


==Verborgen vergelijkingsvraag gebruiken om een ​​antwoord alvast in te vullen==
==Using hidden equation question to autofill an answer==




'''Probleem:'''
'''Problem:'''
Je hebt twee vragen. Vraag 1 vraagt ​​respondenten naar hun leeftijd. Vraag 2 deelt respondenten in drie groepen in: jonger dan 20 jaar, 20 jaar, ouder dan 20 jaar.
Imagine you have two questions Q1 and Q2. Q1 asks respondents for their age. Q2 divides respondents into three groups: age is below 20 years, age is 20, age is greater than 20.  
Dus zou vraag 2 gebruik moeten maken van de waarden "1", "2", "3", die overeenkomen met deze genoemde voorwaarden. Ook moeten we niet vergeten om de vraag te verbergen (onzichtbaar te maken, de vraag zal niet in de enquête worden getoond, maar de waarden zullen wel in de antwoordentabel worden opgeslagen).
So, Q2 should make use of the values "1", "2", "3", which correspond to the above conditions. Also, we should not forget to make Q2 invisible (the question will not be displayed in the survey, but the values will be via the "background process" within the responses table).


'''Sla de gegevens op in de database met behulp van het vraagtype Vergelijking:'''
'''To fill in the database using the Equation question type:'''
* Maak eerst een vraag met code Q1 als een numerieke invoervraag.
* First, create a question with code Q1 as a numerical input question.
* Maak vervolgens een nieuwe vraag met code Q2 als vergelijkingsvraag.
* Then create another question with code Q2 as an equation question.
* Zet in vraag 2 op de tab "Tonen":
* In the "Display settings" tab chapter of Q2:
** het veld "Deze vraag altijd verbergen" op "Aan"
** set "Always hide this question" field as "On"
** tik bij "Vergelijking" de expressie in:
** type in "Equation" field the expression:
<pre> Q2 = if (Q1.NAOK <20, "1", if (Q1.NAOK> 20, "3", "2"))} </pre>
<pre>Q2=if(Q1.NAOK < 20, "1", if(Q1.NAOK > 20, "3", "2"))}</pre>


==Maak een overzichtspagina met behulp van placeholders==
==Create a summary page using placeholders==




Hier laten we zien hoe je aan het einde van de enquête een overzicht kunt maken met alle vragen en antwoorden met behulp van [http://manual.limesurvey.org/Expression_Manager/nl#Toegang_tot_variabelen placeholders]. Het laat ook zien hoe je het overzicht kunt beperken tot beantwoorde vragen.
This tutorial demonstrates how you can create an overview at the end of the survey, listing all questions and answers via [http://manual.limesurvey.org/Expression_Manager#Access_to_Variables Expression Manager placeholders].
It also shows how to limit such an overview to answered questions only.


Voorbeeld: [[Media:Limesurvey_Expression_Manager_Placeholder_Demo_Survey.lss|downloaden]].
Our example can be downloaded from here: [[Media:Limesurvey_Expression_Manager_Placeholder_Demo_Survey.lss|Survey placeholders survey example]].




'''''Hier relevante vraagtypes:'''''
'''''Question types being used here:'''''


'''1. Enkele keuzevragen / enkele tekst / numerieke vragen'''
'''1. Single choice questions / single text/numeric questions'''
* Lijst (Dropdown)
*List (dropdown)
* Lijst (Radioknoppen) [L]
*List (radio) [L]
* Ja / Nee [Y]
*Yes/No [Y]
* Lange vrije tekst [T ]
*Long free text [T]
* Korte vrije tekst [S]
*Short free text [S]
* Numerieke invoer [N]
*Numerical input [N]
* Vergelijking [*]
*Equation [*]




'''2. Vraag met subvragen'''
'''2. Question with subquestions'''
* Meerdere korte vrije teksten [Q]
*Multiple short text [Q]
* Meerkeuze [M]
*Multiple choice [M]
* Array [F]
*Array [F]
* Array (Ja / Nee / Weet niet) [C]
*Array (Yes/No/Uncertain) [C]
* Array (10-puntskeuze) [B]
*Array (10 point choice) [B]




'''3. Vragen met 2 schalen '''
'''3. Questions with 2 scales'''
* Array dubbele schaal [1]
*Array dual scale [1]




'''4. Vragen met X- en Y-schalen '''
'''4. Questions with X and Y scales'''
* Array (getallen) [:]
*Array (Numbers) [:]




'''5. Gesloten vragen'''
'''5. Mask questions'''
* Tekst scherm [X]
*Text display [X]




Simpeler dan dit kunnen we het overzicht niet maken:
In this simple example, our overview will be a simple list with:


- ''Vraagtekst:'' Antwoord van de deelnemer
- ''Question text:'' User's answer




===Enkelekeuzevragen, enkele test- getalvragen===
===Single choice questions / single text/numeric questions===




Voor deze vraagtypes slaat LimeSurvey een waarde op:
For all these question types, Limesurvey will store a single response:


* Lijst (Dropdown)
*List (dropdown)
* Lijst (Radioknoppen)
*List (radio)
* Lijst met opmerkingen
*List with comment
* 5-puntskeuze
*5 point choice
* Ja / Nee
*Yes/No
* Korte vrije tekst
*Short free text
* Lange vrije tekst
*Long free text
* Extra lange vrije tekst
*Huge free text
* Numerieke invoer
*Numerical input
* Vergelijking
*Equation
* Datum
*Date
* Geslacht
*Gender


Als de vraagcode van de vraag q1 is, kunnen we de vraagtekst en het antwoord raadplegen met:
Assuming the question code of the question is q1, we can reference the question text and answer using:


- {q1.question}: {q1.shown}
- {q1.question}: {q1.shown}


Voorbeeld:
Example:


- Hoe oud ben je?: 25
- How old are you?: 25




Als je wilt controleren of die vraag is beantwoord, kun je een IF-statement gebruiken:
If you want to check whether that question was answered you can put an IF statement around your output:


<pre>{if(!is_empty(q1),join("- ",q1.question,": ",q1.shown),"")}</pre>
<pre>{if(!is_empty(q1),join("- ",q1.question,": ",q1.shown),"")}</pre>


Dit wordt "vertaalt" naar: INDIEN vraag met code q1 niet leeg is, uitvoer "- " EN de vraagtekst EN ": " EN de antwoordtekst (de functie join voegt elementen samen als een nieuwe string; ANDERS: geen uitvoer  ("" is een lege string).
This "translates" to: IF question with code q1 is not empty, output "- " AND the question text AND ": " AND the answer text (the join() function joins elements as a new string; ELSE: output nothing ("" means empty string).


===Vraag met subvragen===
===Question with subquestions===




Voor  deze vraagtypen gebruikt LimeSurvey subvragen:
For all these question types LimeSurvey uses subquestions:


*Meerdere korte vrije teksten
*Multiple short text
*Meerkeuzevraag
*Multiple choice
*Meerkeuzevraag met opmerkingen
*Multiple choice with comments
*Array
*Array
*Array (5-puntskeuze)
*Array (5 point choice)
*Array (10-puntskeuze)
*Array (10 point choice)
*Array (Ja/Nee/Weet niet)
*Array (Yes/No/Uncertain)
*Array (Meer/Gelijk/Minder)
*Array (Increase/Same/Decrease)
*Array per kolom
*Array by column


Ervan uitgaande dat de vraagcode van de vraag q2 is en de deelvragen SQ001, SQ002 zijn (automatische nummering uitgevoerd door LimeSurvey), kunnen we de vraag tekst en antwoord raadplegen met:
Assuming the question code of the question is q2 and the subquestions are numbered SQ001, SQ002, (auto-numbering done by LimeSurvey), we can reference the question text and answer using:


- {q2_SQ001.question}: {q2_SQ001.shown}
- {q2_SQ001.question}: {q2_SQ001.shown}
Line 218: Line 217:
- {q2_SQ002.question}: {q2_SQ002.shown}
- {q2_SQ002.question}: {q2_SQ002.shown}


Voor meerkeuzevragen is het logisch om nu de tekst van de aangevinkte subvraag weer te geven en om voor elke geselecteerde optie een Y te tonen:
For multiple choice questions it makes sense to now show the text of the ticked subquestion but to show a Y for each selected option:


- {q2_SQ001.question}: {q2_SQ001}
- {q2_SQ001.question}: {q2_SQ001}
Line 226: Line 225:
...
...


Het is momenteel niet mogelijk om de vraagtekst van vragen met subvragen te tonen, zie [http://bugs.limesurvey.org/view.php?id=8858 wijzingingsverzoek].
Note that currently it is not possible to output the question text of questions with subquestions, see [http://bugs.limesurvey.org/view.php?id=8858 this feature request].




====Voorbeeld 1 (vraagtype is meerkeuze)====
====Example 1 (assuming question type is multiple choice)====




- Ken je deze automerken?
- Do you know these car brands?


-- Mercedes: Y
-- Mercedes: Y
Line 241: Line 240:




Als je alleen geselecteerde items wilt tonen, kun je een IF-statement gebruiken:
If you want to output checked items only you can put an IF statement around your output and check for the checkbox value:


<pre>{ if( q2_SQ001=="Y", join( "- ", q2_SQ001.question, ": ", q2_SQ001.shown ), "" ) }</pre>
<pre>{ if( q2_SQ001=="Y", join( "- ", q2_SQ001.question, ": ", q2_SQ001.shown ), "" ) }</pre>




Gebruik de <i>listifop</i>-functie als je een lijst wilt uitvoeren met alleen de geselecteerde items, bijvoorbeeld: Mercedes, Volvo
Use the <i>listifop</i> function if you want to output a list of only the selected items, eg: Mercedes, Volvo


<pre>{ listifop( 'value', '==', 'Y', 'question', ', ', that.q2.sgqa ) }</pre>
<pre>{ listifop( 'value', '==', 'Y', 'question', ', ', that.q2.sgqa ) }</pre>




Waar &nbsp;<small>that.q2</small>&nbsp; uitgebreid wordt voor alle subvragen van q2. Meer informatie: [[Expression_Manager_-_presentation/nl#Gereserveerde variabelen ('this','self','that')|self, this en that]].
Where &nbsp;<small>that.q2</small>&nbsp; expands to all of q2's subquestions. See [[Expression_Manager_-_presentation#The_reserved_.22this.22.2C_.22self.22.2C_and_.22that.22_variables|self, this and that]] for more detail.


</br>
</br>


====Voorbeeld 2 (vraagtype is Array (10-puntskeuze))====
====Example 2 (assuming question type is Array (10 point choice))====




- Beoordeel de kwaliteit van de onderstaande automerken op een schaal van 1 : zeer slecht tot 10 : zeer goed?
- Please rate the quality of the car brands below on a scale from 1=very bad to 10=very good?


-- Mercedes: 7
-- Mercedes: 7
Line 267: Line 266:




Als je alleen beoordeelde items wilt tonen, kun je een IF-statement gebruiken en testen of de huidige subvraag beantwoordt is :
If you want to output rated items only you can put an IF statement around your output and check if the current sub question was answered by using:


<pre>{ if( ! is_empty( q3_SQ001 ), join( "- ", q3_SQ001.question, ": ", q3_SQ001.shown ), "" ) }</pre>
<pre>{ if( ! is_empty( q3_SQ001 ), join( "- ", q3_SQ001.question, ": ", q3_SQ001.shown ), "" ) }</pre>




Gebruik de functie <i>listifop</i> als je bijvoorbeeld alleen een lijst met geselecteerde items van meer dan acht wilt uitvoeren, bijvoorbeeld: Audi / Volvo
Use the <i>listifop</i> function if for example you want to only output a list of the selected items greater than eight, eg: Audi / Volvo


<pre>{ listifop( 'value', '>', 8, 'question', ' / ', that.q3.sgqa ) }</pre>
<pre>{ listifop( 'value', '>', 8, 'question', ' / ', that.q3.sgqa ) }</pre>
Line 278: Line 277:
</br>
</br>


===Vraag met twee schalen===
===Question with two scales===




{{Note|Dit is alleen van toepassing op het vraagtype dubbele schaal.}}
{{Note|This applies to the dual scale question type only.}}




Laten we aannemen dat de volgende codes worden gebruikt:
Let's assume that the following codes are being used:
*Vraagcode: q4
*Question code: q4
*Subvraagcodes: SQ001, SQ002, ...
*Subquestion codes: SQ001, SQ002, ...
*Antwoordcodes schaal 1: A1, A2, ...
*Answer codes scale 1: A1, A2, ...
*Antwoordcodes schaal 2: B1, B2, ...
*Answer codes scale 2: B1, B2, ...




{{Note|Om te verwijzen naar het resultaat van een bepaalde subvraag op een bepaalde schaal, moet je QuestionCode gebruiken. '_'. SubQuestionCode. '_'. ScaleID. '''Let op: "ScaleID" is 0 voor de eerste schaal en 1 voor de andere!'''</br> Voorbeeld voor verwijzing naar het antwoord op de derde subvraag en tweede schaal: q4_SQ003_1 - vraag 4, deelvraag 3, tweede schaal.}}
{{Note|To refer to the result of a certain subquestion on a certain scale, you need to use QuestionCode . '_' . SubQuestionCode . '_' . ScaleID. '''Note that "ScaleID" is 0 for the first scale and 1 for the other!'''</br> Example for referring to the answer of the third subquestion and second scale: q4_SQ003_1 - Question 4, subquestion 3, second scale.}}




Laten we de resultaten voor zowel de schalen als de eerste twee subvragen weergeven:
Let's output the results for both scales and the first two subquestions:


- {q4_SQ001_0.question}: {q4_SQ001_0.shown} / {q4_SQ001_1.shown}
- {q4_SQ001_0.question}: {q4_SQ001_0.shown} / {q4_SQ001_1.shown}
Line 300: Line 299:
- {q4_SQ002_0.question}: {q4_SQ002_0.shown} / {q4_SQ002_1.shown}
- {q4_SQ002_0.question}: {q4_SQ002_0.shown} / {q4_SQ002_1.shown}


Om de subvraagtekst te tonen, moet je de schaal-ID toevoegen aan de tijdelijke aanduiding (hoewel de teksten voor beide schalen hetzelfde zijn). Dus in plaats van {q4_SQ001.question} moet je {q4_SQ001_0.question} of {q4_SQ001_1.question} gebruiken.
To output the subquestion text, you need to add the scale ID to the placeholder (though the texts are the same for both scales). So instead of {q4_SQ001.question} we have to use {q4_SQ001_0.question} or {q4_SQ001_1.question}.


Als je de resultaten van subvragen met ten minste één antwoord wilt exporteren / weergeven, gebruik dan deze syntaxis voor elke subvraag:
If you want to export/display the results of subquestions with at least one answer only, use this syntax for each subquestion:


<pre>{if(count(q4_SQ001_0,q4_SQ001_1)>0,join("- ",q4_SQ001_0.question,": ",q4_SQ001_0.shown," / ",q4_SQ001_1.shown),"")}</pre>
<pre>{if(count(q4_SQ001_0,q4_SQ001_1)>0,join("- ",q4_SQ001_0.question,": ",q4_SQ001_0.shown," / ",q4_SQ001_1.shown),"")}</pre>


===Vraag met X en Y schaal===
===Question with X and Y scales===




Dit geldt voor alle matrixvragen die een antwoord voor elke cel mogelijk maken (niet alleen elke rij zoals eerder getoond) :
This applies to all matrix questions which allow an answer for every cell (not just every row as shown previously):
* Array (teksten)
*Array Texts
* Array (getallen)
*Array Numbers




Als de gebruikte code als volgt zijn:
Assumed codes used:
* Vraagcode: q5
*Question code: q5
* Subvraagcodes: SQ001, SQ002, ...
*Subquestion codes: SQ001, SQ002, ...
* Antwoordcodes: A1, A2, ...
*Answer codes: A1, A2, ...


Als je naar het resultaat van een bepaalde subvraag in een bepaalde kolom wilt verwijzen, moet je gebruiken VraagCode . '_'. SubvraagCode. '_'. Antwoordcode. Voorbeeld voor het verwijzen naar het antwoord van de derde subvraag en de tweede kolom: q5_SQ003_A2.
To refer to the result of a certain subquestion from a certain column, you need to use QuestionCode . '_' . SubQuestionCode . '_' . AnswerCode. Example for referring to the answer of the third subquestion and second column: q5_SQ003_A2.


Als we de resultaten voor de kolommen 1-3 voor de eerste twee subvragen willen weergeven:
Let's output the results for columns 1-3 of the first two subquestions:


- {q5_SQ001_A1.question}: {q5_SQ001_A1.shown} | {q5_SQ001_A2.shown} | {q5_SQ001_A3.shown}
- {q5_SQ001_A1.question}: {q5_SQ001_A1.shown} | {q5_SQ001_A2.shown} | {q5_SQ001_A3.shown}
Line 328: Line 327:




Aangezien voor deze vraagtypes elke cel (combinatie van X-as en Y-as) gelijk is aan één antwoordoptie, moet voor elke cel een test op bestaande gegevens worden uitgevoerd. Voorbeeld:
Since for these question types each cell (combination of X axes and Y axes) equals one answer option, a test for existing data needs to be done for each cell. Example:


<pre>{if(!is_empty(q5_SQ001_A1),join("- ",q5_SQ001_A1.question,": ",q5_SQ001_A1.shown),"")}</pre>
<pre>{if(!is_empty(q5_SQ001_A1),join("- ",q5_SQ001_A1.question,": ",q5_SQ001_A1.shown),"")}</pre>




{{Note|Om de subvraagtekst te tonen moet je de antwoordcode aan de tijdelijke aanduiding toevoegen (hoewel de teksten voor alle antwoordopties hetzelfde zijn). Dus in plaats van {q5_SQ001.question} moeten je {q5_SQ001_A1.question} of {q5_SQ001_A2.question} gebruiken.}}
{{Note|To output the subquestion text you need to add the answer code to the placeholder (though the texts are the same for all answer options). So instead of {q5_SQ001.question} we have to use {q5_SQ001_A1.question} or {q5_SQ001_A2.question}.}}


==Verberg vraag als er geen antwoord is op voorafgaande vraag==
==Hide question if answer from previous question is empty==




{|class="wikitable"
{|class="wikitable"
|Doel||Vraag verbergen als de voorgaande vraag niet is beantwoordt
|Purpose||Hide question if answer from previous question is empty
|-
|-
|Type||Vraag relevantie
|Type||Question Relevance
|-
|-
|Voorbeeld||Vraag 1: vraagcode "name", vraagtekst "What's your name?" <br /> Vraag 2: vraagtekst "{name}, how old are you?" <br /> Doen: Niet naar leeftijd vragen als er geen naam is ingevuld
|Example||Question one: question code "name", question text "What's your name?" <br /> Question two: question text "{name}, how old are you?" <br /> To do: Hide question two if the textfield of question one is empty
|-
|-
|Expressie||!is_empty(name)
|Expression||!is_empty(name)
|-
|-
|Beschrijving||is_empty() bepaalt of een variabele gevuld is. De "!" draait het resultaat om. Dus als de variabele gevuld is wordt de vraag getoond
|Description||is_empty() determines whether a variable is considered to be empty. The "!" negates the result. So if the variable is not empty the Expression will be true and the question is shown
|-
|-
|Stappen||Maak/wijzig vraag 2<br /> Voer "!is_empty(name)" in bij "Relevantievergelijking:"
|Steps||Create/edit question two <br /> Insert "!is_empty(name)" into "Relevance equation:"
|-
|-
|Voorbeeld||[[Media:Hide_question_if_empty_question_group.zip|downloaden]]
|Sample File||[[Media:Hide_question_if_empty_question_group.zip|Hide_question_if_empty_question_group.zip]]
|-
|-
|colspan="2" align="center"|[[File:Hide question if empty 1.png]][[File:Hide question if empty 2.png]]
|colspan="2" align="center"|[[File:Hide question if empty 1.png]][[File:Hide question if empty 2.png]]
Line 357: Line 356:




==Verberg vraaggroep als antwoord op voorafgaande vraag is Ja of Nee==
==Hide question group if answer from previous question is Yes or No==




{|class="wikitable"
{|class="wikitable"
|Doel||Verberg vraaggroep als antwoord op voorafgaande vraag is Ja of Nee
|Purpose||Hide question group if answer from previous question is Yes or No
|-
|-
|Type||Vraaggroep relevantie
|Type||Question group Relevance
|-
|-
|Voorbeeld||Pagina 1, Vraaggroep 1, Vraag 1: vraagcode code "PET", vraagtekst "Do you have a pet?" -Yes -No <br /> Pagina 2, Vraaggroep 2: Titel "About your pet(s)" <br /> Doen: Tonen/verbergen vraaggroep 2 afhankelijk van antwoord op vraag 1
|Example||Page one, Question Group one, Question one: question code "PET", question text "Do you have a pet?" -Yes -No <br /> Page two, Question Group two: Title "About your pet(s)" <br /> To do: Show/Hide question group two if answer from question one is Yes/No
|-
|-
|Expressie||PET == "Y"
|Expression||PET == "Y"
|-
|-
|Beschrijving||Je wilt het antwoord op de vraag met vraagcode PET controleren. Zonder prefix in ExpressieBeheer is dit "Qcode.code". Dus vergelijk de antwoordcode van PET met de waarde "Y". Als een deelnemer "Yes" antwoordt dan is de expressie waar en wordt de tekst bij vraaggroep 2 "About your pet(s)" getoond.
|Description||PET is the question code for the question you want to check the answer. If you don't use a suffix EM will use "Qcode.code". So you compare the answer code from the PET question to the value "Y". If the participant answers "Yes" the Expression is true and the question group "About your pet(s)" will be shown.
|-
|-
|Stappen||Maak/wijzig vraaggroep 2<br /> Vul "PET == "Y"" in bij  "Relevantievergelijking:"
|Steps||Create/edit question group two <br /> Insert "PET == "Y"" into "Relevance equation:"
|-
|-
|Voorbeeld||[[Media:Hide question group if answer from previous question is Yes or No.zip|downloaden]]
|Sample File||[[Media:Hide question group if answer from previous question is Yes or No.zip|Hide_question group_if_answer_from_previous_question_is_Yes_or_No.zip]]
|-
|-
|colspan="2" align="center"|[[File:Hide question group if answer from previous question is Yes or No 1.png]][[File:Hide question group if answer from previous question is Yes or No 2.png]]
|colspan="2" align="center"|[[File:Hide question group if answer from previous question is Yes or No 1.png]][[File:Hide question group if answer from previous question is Yes or No 2.png]]
Line 379: Line 378:




==Toon waarde van een meerkeuze invoerveld==
==Display value of a multiple answer input question field==




{|class="wikitable"
{|class="wikitable"
|Doel||Toon waarde van een meerkeuze invoerveld
|Purpose||Display value of a multiple answer input question field
|-
|-
|Type||Referentie
|Type||Reference
|-
|-
|Voorbeeld||Vraag 1: vraagcode "AskChildAge", vraagtekst "How old are your children?". Subvraagcodes -Child1 -Child2 -Child3 - ChildXXX <br /> Vraag 2: vraagcode "ReportChildAge" vraagtekst "About your first child: - CHILD1 is AGE1."
|Example||Question one: question code "AskChildAge", question text "How old are your children?". Subquestions codes -Child1 -Child2 -Child3 - ChildXXX <br /> Question two: question code "ReportChildAge" question text "About your first child: - CHILD1 is AGE1."
|-
|-
|Expressie||{AskChildAge_Child1.question}, {AskChildAge_Child1.value}
|Expression||{AskChildAge_Child1.question}, {AskChildAge_Child1.value}
|-
|-
|Beschrijving||Je wilt de waarde van een subvraag gebruiken in de volgende vraag, je kunt die waarde benaderen met de expressie: QcodeQuestion_QcodeSubquestion.value
|Description||You want to use the value of a subquestion in a following question. You can access the subquestion value with this kind of expression: QcodeQuestion_QcodeSubquestion.value
|-
|-
|Stappen||Maak/wijzig vraag 2<br />Vul bij de beschrijving in: "About your first child: - {AskChildAge_Child1.question} is {AskChildAge_Child1.value}."
|Steps||Create/edit the second question <br /> Insert this text in the description: "About your first child: - {AskChildAge_Child1.question} is {AskChildAge_Child1.value}."
|-
|-
|Voorbeeld||[[Media:Display_value_of_a_multiple_answer_input_question_field.zip|downloaden]]
|Sample File||[[Media:Display_value_of_a_multiple_answer_input_question_field.zip|Display_value_of_a_multiple_answer_input_question_field.zip]]
|-
|-
|colspan="2" align="center"|[[File:Display value of a multiple answer input question field 1.png]]
|colspan="2" align="center"|[[File:Display value of a multiple answer input question field 1.png]]
|}
|}


==Valideer het aantal vakjes dat per rij is aangevinkt bij een "Array (getallen)"-vraag ==
==Validate number of boxes ticked per row for an "Array (Numbers) Checkbox" question==




{|class="wikitable"
{|class="wikitable"
|Doel||Valideer aantal per rij geselecteerde boxen
|Purpose||Validate number of boxes ticked per row
|-
|-
|Type||Validatie
|Type||Validation
|-
|-
|Voorbeeld||Vraagtype "Array (getallen) (Checkbox weergave)"
|Example||Question of type "Array Numbers (Checkbox Layout)"
|-
|-
|Expressie||sum(...)
|Expression||sum(...)
|-
|-
|Beschrijving||(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= X) bepaald of minstens X checkboxen in rij A zijn aangevinkt. <br />Als je alle drie rijen wilt controleren (A, B, C), kun je "&&" gebruiken: <br />(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= X) <br />&& (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= X) <br />&& (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= X)
|Description||(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= X) determines whether at least X checkboxes in row A are checked. <br />If you want to check all three rows (A, B, C), you can connect the expression using "&&": <br />(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= X) <br />&& (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= X) <br />&& (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= X)
|-
|-
|Stappen||Maak/wijzig vraagtype "Array (getallen) (Checkbox weergave)".<br /> Vul de gegeven expressie in bij "Vraag validatievergelijking" bij de geavanceerde vraaginstellingen (de naam van de variabele moet je natuurlijk wel aanpassen!).
|Steps||Create/edit question of type "Array Numbers (Checkbox Layout)".<br /> Insert the above expression into "Question validation equation" at the advanced question settings (you might have to adjust variable namings!).
|-
|-
|Voorbeeld||[[Media:limesurvey_survey_53654.lss|downloaden]]
|Sample File||[[Media:limesurvey_survey_53654.lss|Validate number of boxes ticker per row for an Array (Numbers) Checkbox.lss]]
|-
|-
|colspan="2" align="center"|[[File:Validate number of boxes ticker per row for an Array (Numbers) Checkbox 05.png]][[File:Validate number of boxes ticker per row for an Array (Numbers) Checkbox 1.png]]
|colspan="2" align="center"|[[File:Validate number of boxes ticker per row for an Array (Numbers) Checkbox 05.png]][[File:Validate number of boxes ticker per row for an Array (Numbers) Checkbox 1.png]]
|}
|}


==Bereken periode tussen twee datums==
==Calculate difference between two dates==




{| class="wikitable"
{| class="wikitable"
|Doel||Bereken duur periode
|Purpose||Calculate difference between two dates
|-
|-
|Type||Relevantie / vraagtype vergelijking / Validatie
|Type||Relevance / Equation question type / Validation
|-
|-
|Voorbeeld||Vraag 1 (date/time, code: DOB): What is your date of birth? <br /> Vraag 2 (date/time, code: datetoday): What is the date today? <br /> Vraag 3 (boilerplate): You are XXXX days old. <br /> Doen: Bepalen en tonen aantal dagen tussen de ingevulde datums.
|Example||Question one (date/time, code: DOB): What is your date of birth? <br /> Question two (date/time, code: datetoday): What is the date today? <br /> Question three (boilerplate): You are XXXX days old. <br /> To do: Calculate and display the number of days between the date given in question 1 and the question 2.
|-
|-
|Expressie||{(strtotime(datetoday)-strtotime(DOB))/60/60/24}<br>
|Expression||{(strtotime(datetoday)-strtotime(DOB))/60/60/24}<br>
|-
|-
|Beschrijving|| strtotime bepaalt het aantal seconden tussen 1 january 1970 en de meegegeven datum. Dat doen we voor beide datums en kijken dan naar het verschil. Met "/60/60/24" zetten we de seconden weer om naar dagen.  <br /> Je hoeft niet naar de huidige datum te vragen maar je kunt ook strtotime('now') of time() gebruiken, de tijd waarop de deelnemer de enquête invult. Je bepaalt dus de leeftijd met {(time() - strtotime(DOB)) / 60 / 60 / 24 / 365.25}  De datum moet dan wel goed zijn ingevuld, anders werkt de functie strtotime() niet goed.   
|Description|| strtotime calculates the number of seconds between the 1st of January 1970 and the given date. The above expression calculates the number of seconds between the two given dates. The term "/60/60/24" just calculates the number of days from the number of seconds.  <br /> Instead of asking for the "datetoday", you can also use strtotime('now') or simply time(), which directly returns the number of seconds from January 1970 until now (i.e. the time the survey was taken).  Thus you could quickly figure out the age of a person in years with  the equation {(time() - strtotime(DOB)) / 60 / 60 / 24 / 365.25}  In any of these cases, it is critical that the date is entered in a proper format, otherwise the strtotime() function will not work right.   
|-
|-
|Stappen||Maak twee datumvragen aan (geboortedatum en vandaag) en een boilerplate vraag. <br /> Vul als vraagtekst in de boilerplate vraag in: "On {datetoday} you were {(strtotime(today)-strtotime(dob))/60/60/24} days days old." <br /><br />NB: De functie kan veel datumformaten aan, maar niet alle. Gebruik als datumformaat in je enquête mm/dd/yyyy, yyyy-mm-dd of dd.mm.yyyy.
|Steps||Create two date questions (for the date of birth and for today's date) and a boilerplate question. <br /> In the question text of the boilerplate question insert: "On {datetoday} you were {(strtotime(today)-strtotime(dob))/60/60/24} days days old." <br /><br /> Please note: The function strtotime can work with MANY but not all date formats. If you run into problems set your survey's date format to mm/dd/yyyy or yyyy-mm-dd or dd.mm.yyyy"
|-
|-
|Voorbeeld||[[Media:TestSurvey_Working_with_Dates.zip|downloaden]]
|Sample File||[[Media:TestSurvey_Working_with_Dates.zip|Date_difference.zip]]
|-
|-
|colspan="2" align="center"|[[File:Date_difference_example.png]]
|colspan="2" align="center"|[[File:Date_difference_example.png]]
|}
|}


==Gebruik Expressiebeheer voor beoordelingen==
==Using Expression Manager for Assessments==




Hier komt nog een voorbeeld over het gebruik van Expressiebeheer met het [[Question type - Array/nl|vraagtype Array]] en beoordelingen: </br>
Here comes another example on how to use the Expression Manager with [[Question type - Array|Array type questions]] and assessments:</ br>


Stel je hebt 2 arrayvragen en je wilt de resultaten van de berekeningen in de database opslaan. Het is eigenlijk eenvoudig, je moet je arrays maken en testen en een dummy-reactie invullen om te zien of het werkt en je de resultaten op de voltooide pagina krijgt.
Let's say you have 2 array questions and you want to save the results of the calculation data to your database. It is actually simple, you will need to create and test your arrays and submit a dummy response to see if it works and gives you the results in the completed page.




'''Implementatiedetails:'''
'''Implementation details:'''
* Voeg een vraag van vraagtype vergelijking toe
*add a question of type equation
* Voeg de volgende regel toe, aannemende dat Q1 de vraagcode is, terwijl Q2 de tweede is:
*add the following line assuming that Q1 is your array question code while Q2 is the second one:
** <pre> {Sum (Q1_SQ001.value, Q2_SQ001.value)} </pre>
** <pre>{sum(Q1_SQ001.value,Q2_SQ001.value)}</pre>


Hier staat SQ001 voor de standaardcode bij elke subvraag. Als je de subvraagcode wijzigt, pas je de bovenstaande vergelijking natuurlijk ook aan.
Note that SQ001 is the default code for any subquestion. If you change the subquestion code, adjust the equation above accordingly.




==Gebruik em_validation_q in array==
==Using em_validation_q in array==




Je kunt de [[QS:Em_validation_q/nl|vraag validatievergelijking]] gebruiken om een array met een conditie te controleren.
You can use the [[QS:Em_validation_q|question validation equation]] to control an array with any condition.




'''Implementatiedetails:'''
'''Implementation details:'''
* Voor het eerste array: array met enkele keuze
* for the first array : array of single choice
** Vraagcode is ARRAY
** Question code is ARRAY
** Subvraagcode is SQ01, SQ02, SQ03 en SQ04
** Sub question code are SQ01,SQ02,SQ03 and SQ04
** Wijzig de hele vraag validatievergelijking en zet <pre>! is_empty (ARRAY_SQ01) AND ! is_empty (ARRAY_SQ03) </pre>
** update the Whole question validation equation and put <pre>!is_empty(ARRAY_SQ01) and !is_empty(ARRAY_SQ03) </pre>
* Voor het tweede array
* for the second array : array of text
** Vraagcode is ARRAYTEXT
** Question code is ARRAYTEXT
** Subvraag bij Y-as-code zijn SY01, SY02, SY03 en SY04
** Sub question at Y axis code are SY01,SY02,SY03, and SY04
** Wijzig de hele vraag validatievergelijking en zet <pre>count (self.sq_SY01> = 1) AND  count (self.sq_SY03> = 3) </pre>
** Update the Whole question validation equation and put <pre>count(self.sq_SY01 >= 1) and count(self.sq_SY03 >= 3)</pre>

Revision as of 10:20, 3 March 2020

Please help extending this article by adding your own examples. This will help others getting started using the Expression Manager.


Structure

The first part of the article will describe what Expressions can be used for and where to find/add an Expression. The second part provides examples on how to use Expression.


Categories of Expressions

LimeSurvey uses Expressions for the following purposes:


Relevance

Purpose: Hiding question groups/questions

Relevance controls whether a question group or question is shown or hidden. If the result of the Expression is "true" (i.e. 1), the element will be shown. Otherwise (if the result of the Expression is "false" (i.e. 0)), the element will be hidden.

Type Tonen/verbergen Waar staat het Screenshot
Vraaggroep relevantie vraaggroep Vraag aanmaken/aanpassen -> "Relevantievergelijking:"
Vraag relevantie Vraag Vraag aanmaken/aanpassen -> "Relevantievergelijking:"
Subvraaggroep relevantie Subvraag Wijzig subvragen -> "Relevantievergelijking:"


Validation

Purpose: Validate input/actions on questions/subquestions/answers

Validation controls whether the respondent's input into a question or action is valid or not. If the result of the Expression is "true" (i.e. 1), the "good" class will be applied to the element and validation message. Otherwise, if the result of the Expression is "false" (i.e. 0)), the "error" class will be apllied to the element and validation message. You can declare a style for these classes in the template.css.

Type Validates Where to find Screenshot
Question Validation question Create/Edit question -> "Logic tab" -> "Question validation equation"
Subquestion Validation subquestions Create/Edit question -> "Logic tab" -> "Subquestion validation equation"

Text output

Purposes: (Do something) and write out some text

An Expression can be used to write out some text. For example, you can test or calculate something and specify the output depending on the result of the test or calculation. It can also be used to insert the question text, answers, question types, ... of a question used before the Expression is used. Text output can be used everywhere where a text is shown and can return every kind of results.

Use Case Description
Micro tailoring Adjust a text, e.g., write "Mr" or "Mrs" depending on a gender question asked before
Calculation Calculate a value and write it out, e.g., "Your family income is xxx"
Reference Insert a text from an element, e.g., "Your name is xxx. How old are you?"


Answers storing

Purposes: (Do something,) (write out some text) and store something in the database

The Equation Question Type can be used to store something in the database. You can do something with an Expression, show the Equation question (which is similar to a text display) and store the result of the Expression in the database. It stores the answer into the responses table. Then, the result can be used within the statistics feature or it can also be imported into one of the formats provided by the LimeSurvey export functionality.

Examples for Expressions

Insert an answer from a previous question

Purpose Insert an answer from a previous question
Type Reference
Example Question one (question code "Q00"): What city do you live in?
Question two (question code "Q01") How long have you lived in CITY?
To do: The answer from question one should be used instead of "CITY" from the second question.
Expression {QOO}
Description The answer provided in Q00 replaces the Q00 field from the second question
Steps Create/Edit question two
Insert "How long have you lived in {QOO} (years)?" into the question text field

Using hidden equation question to autofill an answer

Problem: Imagine you have two questions Q1 and Q2. Q1 asks respondents for their age. Q2 divides respondents into three groups: age is below 20 years, age is 20, age is greater than 20. So, Q2 should make use of the values "1", "2", "3", which correspond to the above conditions. Also, we should not forget to make Q2 invisible (the question will not be displayed in the survey, but the values will be via the "background process" within the responses table).

To fill in the database using the Equation question type:

  • First, create a question with code Q1 as a numerical input question.
  • Then create another question with code Q2 as an equation question.
  • In the "Display settings" tab chapter of Q2:
    • set "Always hide this question" field as "On"
    • type in "Equation" field the expression:
Q2=if(Q1.NAOK < 20, "1", if(Q1.NAOK > 20, "3", "2"))}

Create a summary page using placeholders

This tutorial demonstrates how you can create an overview at the end of the survey, listing all questions and answers via Expression Manager placeholders. It also shows how to limit such an overview to answered questions only.

Our example can be downloaded from here: Survey placeholders survey example.


Question types being used here:

1. Single choice questions / single text/numeric questions

  • List (dropdown)
  • List (radio) [L]
  • Yes/No [Y]
  • Long free text [T]
  • Short free text [S]
  • Numerical input [N]
  • Equation [*]


2. Question with subquestions

  • Multiple short text [Q]
  • Multiple choice [M]
  • Array [F]
  • Array (Yes/No/Uncertain) [C]
  • Array (10 point choice) [B]


3. Questions with 2 scales

  • Array dual scale [1]


4. Questions with X and Y scales

  • Array (Numbers) [:]


5. Mask questions

  • Text display [X]


In this simple example, our overview will be a simple list with:

- Question text: User's answer


Single choice questions / single text/numeric questions

For all these question types, Limesurvey will store a single response:

  • List (dropdown)
  • List (radio)
  • List with comment
  • 5 point choice
  • Yes/No
  • Short free text
  • Long free text
  • Huge free text
  • Numerical input
  • Equation
  • Date
  • Gender

Assuming the question code of the question is q1, we can reference the question text and answer using:

- {q1.question}: {q1.shown}

Example:

- How old are you?: 25


If you want to check whether that question was answered you can put an IF statement around your output:

{if(!is_empty(q1),join("- ",q1.question,": ",q1.shown),"")}

This "translates" to: IF question with code q1 is not empty, output "- " AND the question text AND ": " AND the answer text (the join() function joins elements as a new string; ELSE: output nothing ("" means empty string).

Question with subquestions

For all these question types LimeSurvey uses subquestions:

  • Multiple short text
  • Multiple choice
  • Multiple choice with comments
  • Array
  • Array (5 point choice)
  • Array (10 point choice)
  • Array (Yes/No/Uncertain)
  • Array (Increase/Same/Decrease)
  • Array by column

Assuming the question code of the question is q2 and the subquestions are numbered SQ001, SQ002, (auto-numbering done by LimeSurvey), we can reference the question text and answer using:

- {q2_SQ001.question}: {q2_SQ001.shown}

- {q2_SQ002.question}: {q2_SQ002.shown}

For multiple choice questions it makes sense to now show the text of the ticked subquestion but to show a Y for each selected option:

- {q2_SQ001.question}: {q2_SQ001}

- {q2_SQ002.question}: {q2_SQ002}

...

Note that currently it is not possible to output the question text of questions with subquestions, see this feature request.


Example 1 (assuming question type is multiple choice)

- Do you know these car brands?

-- Mercedes: Y

-- Audi: N

-- Volvo: Y


If you want to output checked items only you can put an IF statement around your output and check for the checkbox value:

{ if( q2_SQ001=="Y", join( "- ", q2_SQ001.question, ": ", q2_SQ001.shown ), "" ) }


Use the listifop function if you want to output a list of only the selected items, eg: Mercedes, Volvo

{ listifop( 'value', '==', 'Y', 'question', ', ', that.q2.sgqa ) }


Where  that.q2  expands to all of q2's subquestions. See self, this and that for more detail.


Example 2 (assuming question type is Array (10 point choice))

- Please rate the quality of the car brands below on a scale from 1=very bad to 10=very good?

-- Mercedes: 7

-- Audi: 9

-- Volvo: 9


If you want to output rated items only you can put an IF statement around your output and check if the current sub question was answered by using:

{ if( ! is_empty( q3_SQ001 ), join( "- ", q3_SQ001.question, ": ", q3_SQ001.shown ), "" ) }


Use the listifop function if for example you want to only output a list of the selected items greater than eight, eg: Audi / Volvo

{ listifop( 'value', '>', 8, 'question', ' / ', that.q3.sgqa ) }


Question with two scales

This applies to the dual scale question type only.


Let's assume that the following codes are being used:

  • Question code: q4
  • Subquestion codes: SQ001, SQ002, ...
  • Answer codes scale 1: A1, A2, ...
  • Answer codes scale 2: B1, B2, ...


To refer to the result of a certain subquestion on a certain scale, you need to use QuestionCode . '_' . SubQuestionCode . '_' . ScaleID. Note that "ScaleID" is 0 for the first scale and 1 for the other!
Example for referring to the answer of the third subquestion and second scale: q4_SQ003_1 - Question 4, subquestion 3, second scale.


Let's output the results for both scales and the first two subquestions:

- {q4_SQ001_0.question}: {q4_SQ001_0.shown} / {q4_SQ001_1.shown}

- {q4_SQ002_0.question}: {q4_SQ002_0.shown} / {q4_SQ002_1.shown}

To output the subquestion text, you need to add the scale ID to the placeholder (though the texts are the same for both scales). So instead of {q4_SQ001.question} we have to use {q4_SQ001_0.question} or {q4_SQ001_1.question}.

If you want to export/display the results of subquestions with at least one answer only, use this syntax for each subquestion:

{if(count(q4_SQ001_0,q4_SQ001_1)>0,join("- ",q4_SQ001_0.question,": ",q4_SQ001_0.shown," / ",q4_SQ001_1.shown),"")}

Question with X and Y scales

This applies to all matrix questions which allow an answer for every cell (not just every row as shown previously):

  • Array Texts
  • Array Numbers


Assumed codes used:

  • Question code: q5
  • Subquestion codes: SQ001, SQ002, ...
  • Answer codes: A1, A2, ...

To refer to the result of a certain subquestion from a certain column, you need to use QuestionCode . '_' . SubQuestionCode . '_' . AnswerCode. Example for referring to the answer of the third subquestion and second column: q5_SQ003_A2.

Let's output the results for columns 1-3 of the first two subquestions:

- {q5_SQ001_A1.question}: {q5_SQ001_A1.shown} | {q5_SQ001_A2.shown} | {q5_SQ001_A3.shown}

- {q5_SQ002_A1.question}: {q5_SQ002_A1.shown} | {q5_SQ002_A2.shown} | {q5_SQ002_A3.shown}


Since for these question types each cell (combination of X axes and Y axes) equals one answer option, a test for existing data needs to be done for each cell. Example:

{if(!is_empty(q5_SQ001_A1),join("- ",q5_SQ001_A1.question,": ",q5_SQ001_A1.shown),"")}


To output the subquestion text you need to add the answer code to the placeholder (though the texts are the same for all answer options). So instead of {q5_SQ001.question} we have to use {q5_SQ001_A1.question} or {q5_SQ001_A2.question}.

Hide question if answer from previous question is empty

Purpose Hide question if answer from previous question is empty
Type Question Relevance
Example Question one: question code "name", question text "What's your name?"
Question two: question text "{name}, how old are you?"
To do: Hide question two if the textfield of question one is empty
Expression !is_empty(name)
Description is_empty() determines whether a variable is considered to be empty. The "!" negates the result. So if the variable is not empty the Expression will be true and the question is shown
Steps Create/edit question two
Insert "!is_empty(name)" into "Relevance equation:"
Sample File Hide_question_if_empty_question_group.zip


Hide question group if answer from previous question is Yes or No

Purpose Hide question group if answer from previous question is Yes or No
Type Question group Relevance
Example Page one, Question Group one, Question one: question code "PET", question text "Do you have a pet?" -Yes -No
Page two, Question Group two: Title "About your pet(s)"
To do: Show/Hide question group two if answer from question one is Yes/No
Expression PET == "Y"
Description PET is the question code for the question you want to check the answer. If you don't use a suffix EM will use "Qcode.code". So you compare the answer code from the PET question to the value "Y". If the participant answers "Yes" the Expression is true and the question group "About your pet(s)" will be shown.
Steps Create/edit question group two
Insert "PET == "Y"" into "Relevance equation:"
Sample File Hide_question group_if_answer_from_previous_question_is_Yes_or_No.zip


Display value of a multiple answer input question field

Purpose Display value of a multiple answer input question field
Type Reference
Example Question one: question code "AskChildAge", question text "How old are your children?". Subquestions codes -Child1 -Child2 -Child3 - ChildXXX
Question two: question code "ReportChildAge" question text "About your first child: - CHILD1 is AGE1."
Expression {AskChildAge_Child1.question}, {AskChildAge_Child1.value}
Description You want to use the value of a subquestion in a following question. You can access the subquestion value with this kind of expression: QcodeQuestion_QcodeSubquestion.value
Steps Create/edit the second question
Insert this text in the description: "About your first child: - {AskChildAge_Child1.question} is {AskChildAge_Child1.value}."
Sample File Display_value_of_a_multiple_answer_input_question_field.zip

Validate number of boxes ticked per row for an "Array (Numbers) Checkbox" question

Purpose Validate number of boxes ticked per row
Type Validation
Example Question of type "Array Numbers (Checkbox Layout)"
Expression sum(...)
Description (sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= X) determines whether at least X checkboxes in row A are checked.
If you want to check all three rows (A, B, C), you can connect the expression using "&&":
(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= X)
&& (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= X)
&& (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= X)
Steps Create/edit question of type "Array Numbers (Checkbox Layout)".
Insert the above expression into "Question validation equation" at the advanced question settings (you might have to adjust variable namings!).
Sample File Validate number of boxes ticker per row for an Array (Numbers) Checkbox.lss

Calculate difference between two dates

Purpose Calculate difference between two dates
Type Relevance / Equation question type / Validation
Example Question one (date/time, code: DOB): What is your date of birth?
Question two (date/time, code: datetoday): What is the date today?
Question three (boilerplate): You are XXXX days old.
To do: Calculate and display the number of days between the date given in question 1 and the question 2.
Expression {(strtotime(datetoday)-strtotime(DOB))/60/60/24}
Description strtotime calculates the number of seconds between the 1st of January 1970 and the given date. The above expression calculates the number of seconds between the two given dates. The term "/60/60/24" just calculates the number of days from the number of seconds.
Instead of asking for the "datetoday", you can also use strtotime('now') or simply time(), which directly returns the number of seconds from January 1970 until now (i.e. the time the survey was taken). Thus you could quickly figure out the age of a person in years with the equation {(time() - strtotime(DOB)) / 60 / 60 / 24 / 365.25} In any of these cases, it is critical that the date is entered in a proper format, otherwise the strtotime() function will not work right.
Steps Create two date questions (for the date of birth and for today's date) and a boilerplate question.
In the question text of the boilerplate question insert: "On {datetoday} you were {(strtotime(today)-strtotime(dob))/60/60/24} days days old."

Please note: The function strtotime can work with MANY but not all date formats. If you run into problems set your survey's date format to mm/dd/yyyy or yyyy-mm-dd or dd.mm.yyyy"
Sample File Date_difference.zip

Using Expression Manager for Assessments

Here comes another example on how to use the Expression Manager with Array type questions and assessments:</ br>

Let's say you have 2 array questions and you want to save the results of the calculation data to your database. It is actually simple, you will need to create and test your arrays and submit a dummy response to see if it works and gives you the results in the completed page.


Implementation details:

  • add a question of type equation
  • add the following line assuming that Q1 is your array question code while Q2 is the second one:
    • {sum(Q1_SQ001.value,Q2_SQ001.value)}

Note that SQ001 is the default code for any subquestion. If you change the subquestion code, adjust the equation above accordingly.


Using em_validation_q in array

You can use the question validation equation to control an array with any condition.


Implementation details:

  • for the first array : array of single choice
    • Question code is ARRAY
    • Sub question code are SQ01,SQ02,SQ03 and SQ04
    • update the Whole question validation equation and put
      !is_empty(ARRAY_SQ01) and !is_empty(ARRAY_SQ03) 
  • for the second array : array of text
    • Question code is ARRAYTEXT
    • Sub question at Y axis code are SY01,SY02,SY03, and SY04
    • Update the Whole question validation equation and put
      count(self.sq_SY01 >= 1) and count(self.sq_SY03 >= 3)