Actions

Expression Manager sample surveys: Difference between revisions

From LimeSurvey Manual

m (Text replacement - " enclose="div"" to "")
 
(44 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<languages />
<translate>


<!--T:1-->
__TOC__
__TOC__




=Introduction=
=Introduction= <!--T:2-->




The best way to learn how to use the Expression Manager is to play with working examples and modify them to your needs.
<!--T:3-->
The best way to learn how to use the ExpressionScript is to play with working examples and modify them to your needs.


<!--T:4-->
You may find below a set of sample surveys to demonstrate (and test) how the EM can be used to enhance your survey. These surveys can be found in the distribution's /docs/demosurveys folder.  
You may find below a set of sample surveys to demonstrate (and test) how the EM can be used to enhance your survey. These surveys can be found in the distribution's /docs/demosurveys folder.  




=Relevance, Tailoring and Equations=
=Relevance, Tailoring and Equations= <!--T:5-->




==Overview==
==Overview== <!--T:6-->




To access the survey sample, please click on the following link: [[Media:LS3_em_tailoring.zip|LS3_em_tailoring.zip]]
<!--T:7-->
The following example computes the BMI (Body Mass Index) of each respondent. See below the features that are demonstrated within this example.


==EM Features Demonstrated==
==EM Features Demonstrated== <!--T:8-->
   
   


<!--T:9-->
#'''Relevance''' - support for powerful conditional logic;
#'''Relevance''' - support for powerful conditional logic;
#'''Piping / Tailoring''' - offers the ability to pipe or tailor answers and question metadata;
#'''Piping / Tailoring''' - offers the ability to pipe or tailor answers and question metadata;
Line 30: Line 37:




==Screenshots==
==Screenshots== <!--T:10-->




<!--T:11-->
This example computes the Body Mass Index, a calculation of your weight and height to determine whether you are overweight. Note that initially, all you see are the four mandatory questions:
This example computes the Body Mass Index, a calculation of your weight and height to determine whether you are overweight. Note that initially, all you see are the four mandatory questions:




<!--T:12-->
<center>[[File:tailoring1.jpg]]</center>
<center>[[File:tailoring1.jpg]]</center>




<!--T:13-->
Once you enter your information (and you get to choose whether to use metric or non-metric units), you see a tailored report that summarizes what you entered, telling you your weight status:
Once you enter your information (and you get to choose whether to use metric or non-metric units), you see a tailored report that summarizes what you entered, telling you your weight status:




<!--T:14-->
<center>[[File:tailoring2.jpg]]</center>
<center>[[File:tailoring2.jpg]]</center>




<!--T:15-->
Here is a different example, using non-metric units to show how the result changes dynamically:  
Here is a different example, using non-metric units to show how the result changes dynamically:  




<!--T:16-->
<center>[[File:tailoring3.jpg]]</center>
<center>[[File:tailoring3.jpg]]</center>




<!--T:17-->
There are hidden [[Question type - Equation|Equation-type questions]] at the internal level that converts the data to metric (if needed), storing the metric height, weight, BMI, and weight status in the database without needing custom JavaScript.
There are hidden [[Question type - Equation|Equation-type questions]] at the internal level that converts the data to metric (if needed), storing the metric height, weight, BMI, and weight status in the database without needing custom JavaScript.


<!--T:18-->
You can see in the next set of examples how you can use mathematical and other functions within tailored reports. This is how the page looks like before you enter any data.  There is conditional logic to show blank cells if no (or non-numeric) data is entered, rather than showing "NaN" or "Divide by Zero".
You can see in the next set of examples how you can use mathematical and other functions within tailored reports. This is how the page looks like before you enter any data.  There is conditional logic to show blank cells if no (or non-numeric) data is entered, rather than showing "NaN" or "Divide by Zero".




<!--T:19-->
<center>[[File:tailoring4.jpg]]</center>
<center>[[File:tailoring4.jpg]]</center>




<!--T:20-->
As numbers are entered, the on-page report changes to show the computation being performed, and its result.
As numbers are entered, the on-page report changes to show the computation being performed, and its result.




<!--T:21-->
<center>[[File:tailoring5.jpg]]</center>
<center>[[File:tailoring5.jpg]]</center>




<!--T:22-->
There are many other examples in this sample survey. For example, the below screenshot shows one of the dozens of ways you can fill out the Dynamic Relevance page. As the help text notes, try different ages, and especially illogical combinations of responses to see the amusing messages generated at the bottom. Also note that if you say that you have more than one child, the message will say "I hope you enjoy playing with your X children", rather than saying "I hope you enjoy playing with your child". This shows how you can easily micro-tailor sentences to make them match the gender and/or number of your subjects. You can even easily conjugate verbs and decline nouns based upon gender and number.
There are many other examples in this sample survey. For example, the below screenshot shows one of the dozens of ways you can fill out the Dynamic Relevance page. As the help text notes, try different ages, and especially illogical combinations of responses to see the amusing messages generated at the bottom. Also note that if you say that you have more than one child, the message will say "I hope you enjoy playing with your X children", rather than saying "I hope you enjoy playing with your child". This shows how you can easily micro-tailor sentences to make them match the gender and/or number of your subjects. You can even easily conjugate verbs and decline nouns based upon gender and number.




<!--T:23-->
<center>[[File:tailoring6.jpg]]</center>
<center>[[File:tailoring6.jpg]]</center>


=Sample Census=


==Download== <!--T:24-->


==Overview==


<!--T:25-->
To access the survey sample, please click on the following link: [[Media:LS3_em_tailoring.zip|LS3_em_tailoring.zip]].


=Sample Census= <!--T:26-->
==Overview== <!--T:27-->
<!--T:28-->
This is a census example that asks how many people are in your household.
This is a census example that asks how many people are in your household.


<!--T:29-->
It demonstrates how group-level relevance can make it easier to implement a "loop" of questions. After creating the group for Person 1, I exported the group. Since I used qcode variable names like p1_name instead of the SGQA code, I could use a text editor to quickly edit and re-import the group several times (e.g., it took about 10 seconds to edit and re-import each repeating group, ensuring that all variables had unique variables names and that the group-level logic was correct).
It demonstrates how group-level relevance can make it easier to implement a "loop" of questions. After creating the group for Person 1, I exported the group. Since I used qcode variable names like p1_name instead of the SGQA code, I could use a text editor to quickly edit and re-import the group several times (e.g., it took about 10 seconds to edit and re-import each repeating group, ensuring that all variables had unique variables names and that the group-level logic was correct).


You can also the [[Copy questions|copy question]] feature, but it won't be as fast as the option suggested above.
<!--T:30-->
You can also the [[Copy question|copy question]] feature, but it won't be as fast as the option suggested above.


<!--T:31-->
This also shows how you can prevent the Finished message from appearing until the survey is truly finished (e.g., when all needed groups are completed).
This also shows how you can prevent the Finished message from appearing until the survey is truly finished (e.g., when all needed groups are completed).




==EM Features Demonstrated==
==EM Features Demonstrated== <!--T:32-->




<!--T:33-->
#'''Group-level relevance''' - The follow-up groups (Person 1-5) only show for up to the number of cohabitants specified;
#'''Group-level relevance''' - The follow-up groups (Person 1-5) only show for up to the number of cohabitants specified;
#'''Tailoring''' - The final report summarizes the demographic data for each cohabitant;
#'''Tailoring''' - The final report summarizes the demographic data for each cohabitant;
Line 93: Line 125:




==Screenshots==
==Screenshots== <!--T:34-->




<!--T:35-->
The survey generates a tailored report showing the demographics of the specified number of cohabitants:
The survey generates a tailored report showing the demographics of the specified number of cohabitants:




<!--T:36-->
<center>[[File:census.jpg]]</center>
<center>[[File:census.jpg]]</center>




<!--T:37-->
If you switch to question-at-a-time mode, you see that the index tailors the questions. Since the user said that the person is a woman, it asks "What is her name".  And since we answered "Mary", the next question says "How old is Mary"?
If you switch to question-at-a-time mode, you see that the index tailors the questions. Since the user said that the person is a woman, it asks "What is her name".  And since we answered "Mary", the next question says "How old is Mary"?




<!--T:38-->
<center>[[File:census2.jpg]]</center>
<center>[[File:census2.jpg]]</center>




==Download==
==Download== <!--T:39-->




[[Media:LS3_group_relevance.zip|LS3_group_relevance.zip]]
<!--T:40-->
To download the survey sample, click here: [[Media:LS3_group_relevance.zip|LS3_group_relevance.zip]].


=Cascading Array Filters=


=Cascading Array Filters= <!--T:41-->


==Overview==


==Overview== <!--T:42-->


This survey is based on the design of a survey courtesy of Joy Lane Research, LLC. They identified a bug in 1.91+ which prevented proper use of cascading array filters.  In 1.91+, say you first pick several options from Q01 and Q02, then pick a favorite from Q04.  If you uncheck the favorite option in Q01, that option does not disappear from Q04.   We also discovered the 'other' option was not being handled correctly. This survey shows that LimeSurvey 1.92 with Expression Manager makes the cascading work correctly.   It also lets us pick an 'other' option and have its label carry through to subsequent questions.  This survey also shows that you can simultaneously use array_filter and array_filter_exclude (see question Q05).


<!--T:43-->
This survey is based on the design of a survey courtesy of Joy Lane Research, LLC.


==Screenshots==


==Screenshots== <!--T:44-->


<!--T:45-->
In the following, note that:
In the following, note that:
*Q02 only shows the set of products checked in Q01 (by using array_filter)
*Q02 only shows the set of products checked in Q01 (by using array_filter)
Line 132: Line 172:




<!--T:46-->
<center>[[File:cascading_array_filter.jpg]]</center>
<center>[[File:cascading_array_filter.jpg]]</center>




Here, note the new behavior of array_filter_exclude (compared to version 1.91+):
<!--T:47-->
*If the exclusive option is selected, it hides all of the other choices, rather than disabling them
<center>[[File:cascading_array_filter2.jpg]]</center>
*The exclusive option cascades as expected (in 1.91+, you would still see questions Q04 and Q05)
*The underlying values are not cleared (as they are in 1.91+), so, if you uncheck the exclusive option, you will see the first screen shot again.
 


<center>[[File:cascading_array_filter2.jpg]]</center>


==Download== <!--T:48-->


==Download==


<!--T:49-->
Click on the following link to download the above example: [[Media:ls2_cascading_array_filter.lss|LS2_cascading_array_filter survey example]].


[[Media:ls2_cascading_array_filter.lss|ls2_cascading_array_filter.lss]]


=Piping/Tailoring Using All Question Types and Attributes= <!--T:50-->


=Piping/Tailoring Using All Question Types and Attributes=


==Overview== <!--T:51-->


==Overview==


<!--T:52-->
If you are confused about how to name your variables (SGQA vs Qcodes), you are not alone. Although the main documentation describes [[ExpressionScript#Access to Variables|how to compose Qcode variable names]], nothing beats seeing it in a working demo.  This survey shows how you can access question attributes and responses using the ExpressionScript.


If you are confused about how to name your variables (whether using the SGQA naming from 1.91+, or the new Qcode naming from 1.92), you are not alone.  Although the main documentation describes [[Expression Manager#Access to Variables|how to compose Qcode variable names]], nothing beats seeing it in a working demo.  This survey shows how you can access question attributes and responses using the Expression Manager.


Caution - we recommend turning off the built-in HTML editor (or converting it to the pop-up mode) when editing this survey. It can take a minute or more for the HTML editor to render the large HTML reports in edit mode.
<!--T:53-->
{{Note|For this example, we recommend turning off the built-in HTML editor (or converting it to the pop-up mode) when editing this survey. It can take a minute or more for the HTML editor to render the large HTML reports in edit mode.}}




==Features==
==Content== <!--T:54-->




<!--T:55-->
*Examples of every question type
*Examples of every question type
*All questions types that can use "other" have it included so you can see how that affects variable naming
*All questions types that can use "other" are included so that you can see how that affects variable naming
*Default values for all question type that accepts defaults
*Default values for all the question types that accepts defaults
*Tailoring - On and Off-Page Reports showing all 16 available EM dot notation suffixes.
*Tailoring - On- and off-page reports showing all 16 available EM dot notation suffixes.
*These reports show all of the currently entered data (so show you how you could generate your own printable reports for users in lieu of the print-answers screen)
*These reports show all of the currently entered data (so show you how you could generate your own printable reports for users in lieu of the print-answers screen)
*Proper Qcode and SGQA naming of all variables
*Proper Qcode and SGQA naming of all variables




==Screenshots==
==Screenshots== <!--T:56-->




This is a huge survey, so we chose not to include screen shots.  Instead, please download and play with it.
<!--T:57-->
This is a huge survey, so we chose not to include screen shots. Instead, please download and play with it.




==Download==
==Download== <!--T:58-->




[[Media:ls2_EM_question_attributes.lss|ls2_EM_question_attributes.lss]]
<!--T:59-->
Click on the following link to download the survey: [[Media:ls2_EM_question_attributes.lss|LS3_EM_question_attributes.lss]]




=Traditional Validation, Re-envisioned=
=Traditional validation, re-envisioned= <!--T:60-->




==Overview==
==Overview== <!--T:61-->




This demonstrates all of the types of validation that can use expressions, and how they affect each of the question types that support validation.  In many cases, the validation tips start hidden and only appear if a question fails validation criteria  (thus also disappearing once the question passes validation criteria again).  These validation types are available for a broader range of question types than in 1.91+.
<!--T:62-->
This demonstrates all the validation types that make use of expressions and how they affect each of the question types that support validation. In many cases, the validation tips start hidden and only appear if a question fails validation criteria (thus also disappearing once the question passes the validation criteria).  




==Validation Types Demonstrated==
==Validation Types Demonstrated== <!--T:63-->




#'''min_num_value_n''' - minimum value for an answer
<!--T:64-->
#'''max_num_value_n''' - max value for an answer
#[[QS:Min_num_value_n|min_num_value_n]] - minimum value for an answer
#'''min_answers''' - minimum number of answers required
#[[QS:Max_num_value_n|max_num_value_n]] - max value for an answer
#'''max_answers''' maximum number of answers allowed
#[[QS:Min_answers|min_answers]] - minimum number of answers required
#'''multiflexible_min''' - minimum value allowed for an answer (for multiflexi numbers question type)
#[[QS:Max_answers|max_answers]] maximum number of answers allowed
#'''multiflexible_max''' - maximum value allowed for an answer (for multiflexi numbers question type)
#[[QS:Multiflexible_min|multiflexible_min]] - minimum value allowed for an answer (for multiflexi numbers question type)
#'''min_num_value''' - minimum allowed sum across all answers for the question
#[[QS:Multiflexible_max|multiflexible_max]] - maximum value allowed for an answer (for multiflexi numbers question type)
#'''max_num_value''' - maximum allowed sum across all answers for the question
#[[QS:Min_num_value|min_num_value]] - minimum allowed sum across all answers for the question
#'''equals_num_value''' - the sum across all answers for the question must equal this value
#[[QS:Max_num_value|max_num_value]] - maximum allowed sum across all answers for the question
#'''validation''' - this is the regular expression validation for the question - it can apply to individual cells
#[[QS:Equals_num_value|equals_num_value]] - the sum across all answers for the question must equal this value
#[[QS:Preg_validation|validation]] - this is the regular expression validation for the question - it can apply to individual cells




==Screenshots==
==Screenshots== <!--T:65-->




Using new CSS styles, each validation type shows up a separate tip.  If shown (they can be hidden via the hide_tip option), the default option is to show them as pink if the question will fail validation constraints, and green if it will pass them.
<!--T:66-->
Using new CSS styles, each validation type shows up a separate tip. If they are shown, they can be hidden via the hide_tip option. The default option is to show them with red font if the question fails the validation criteria, and green if it passes them:




<!--T:67-->
<center>[[File:validation1.jpg]]</center>
<center>[[File:validation1.jpg]]</center>




If the user submits a page with validation errors, the page will be re-shown, but this time the validation errors will be shown in red.
<!--T:68-->
A user cannot submit a page with validation errors. They will be immediately warned if they entered wrong information:




<center>[[File:validation2.jpg]]</center>
<!--T:69-->
<center>[[File:validation3.jpg]]</center>




This color coding also applies to validation sums.
<!--T:70-->
Validation can be applied to individual cells within an array, such as in this example where regular expression validations ensure that each entry is a properly formatted US phone number including area code.




<center>[[File:validation3.jpg]]</center>
<!--T:71-->
<center>[[File:validation4.jpg]]</center>




Validation can be applied to individual cells within an array, such as this example where regular expression validations ensure that each entry is a properly formatted US phone number including area code.
==Download== <!--T:72-->




<center>[[File:validation4.jpg]]</center>
<!--T:73-->
To download the above example, click on the following link: [[Media:LS3_Validation_tests.zip|LS3_Validation_tests.zip]].




==Download==
=Validation Equations= <!--T:74-->




[[Media:ls2_validation_tests.lss|ls2_validation_tests.lss]]
==Overview== <!--T:75-->




=Validation Equations=
<!--T:76-->
Sometimes you need custom validation that cannot be achieved using the traditional min/max criteria. For this, you will need to use the em_validation_q and em_validation_sq options which let you construct complex validation equations at the question and subquestion level, respectively.




==Overview==
<!--T:77-->
{{Note|At the subquestion level, we also introduce the "this" variable to make it easy to validate each cell in an array without needing to know its variable name. For more details about it, click here.}}




Sometimes you need custom validation that cannot be achieved using the traditional min/max criteria.  Enter the new em_validation_q and em_validation_sq options that let you construct complex validation equations at the question and sub-question level, respectively.  Especially for the sub-question-level, we also introduce the "this" variable to make it easy to validate each cell in an array without needing to know its variable name.
==EM Features Demonstrated== <!--T:78-->




==EM Features Demonstrated==
<!--T:79-->
#[[QS:Em_validation_q|em_validation_q]] - this is an equation that determines whether the whole question is valid
#[[QS:Em_validation_q_tip|em_validation_q_tip]] - this is the message to show if the question fails em_validation_q criteria
#[[QS:Em_validation_sq|em_validation_sq]] - this is the equation that determines whether each subquestion (array cell) is valid
#[[QS:Em_validation_sq_tip|em_validation_sq_tip]] - this is the message to show if any of the subquestions is invalid.


<!--T:80-->
In general, when em_validation_sq is used, if any cell is invalid, the background color for that cell turns red to indicate that there is an error.


#'''em_validation_q''' - this is an equation that determines whether the whole question is valid
#'''em_validation_q_tip''' - this is the message to show if the question fails em_validation_q criteria
#'''em_validation_sq''' - this is the equation that determines whether each sub-question (array cell) is valid
#'''em_validation_sq_tip''' - this is the message to show if any of the sub-questions is invalid.


In general, when em_validation_sq is used, if any cell is invalid, the background color for that cell turns pink to indicate that there is an error.
==Screenshots== <!--T:81-->




==Screen Shots==
<!--T:82-->
<center>[[File:sqvalidation.jpg]]</center>




<center>[[File:sqvalidation.jpg]]</center>
<!--T:83-->
This question ensures that you enter the ages of your children in descending order by applying this validation equation:


<!--T:84-->
<syntaxhighlight lang="php">q1_sq1 >= q1_sq2 && q1_sq2 >= q1_sq3 && q1_sq3 >= q1_sq4</syntaxhighlight>


This question ensures that you enter the ages of your children in descending order by applying this validation  equation:


<syntaxhighlight lang="php" enclose="div">q1_sq1 >= q1_sq2 && q1_sq2 >= q1_sq3 && q1_sq3 >= q1_sq4</syntaxhighlight>
<!--T:85-->
<center>[[File:sqvalidation2.jpg]]</center>




<center>[[File:sqvalidation2.jpg]]</center>
<!--T:86-->
<hr width="50%" style="margin:auto">  




This question ensures that no more than 3 questions are answered on any given row by applying this validation equation
<!--T:87-->
In the below example, the validation ensures that no more than 3 questions are answered on any given row by applying this validation equation:


<syntaxhighlight lang="php" enclose="div">(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= 3) && (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= 3) && (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= 3)</syntaxhighlight>
<!--T:88-->
<syntaxhighlight lang="php">(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= 3) && (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= 3) && (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= 3)</syntaxhighlight>


You can also write this as follows, and LimeSurvey automatically converts it at run-time to the above-listed expression.
<!--T:89-->
You can also write this as follows, LimeSurvey automatically converting it at run-time to the above-listed expression.


<syntaxhighlight lang="php" enclose="div">(sum(self.sq_A) <= 3) && (sum(self.sq_B) <= 3) && (sum(self.sq_C) <= 3)</syntaxhighlight>
<!--T:90-->
<syntaxhighlight lang="php">(sum(self.sq_A) <= 3) && (sum(self.sq_B) <= 3) && (sum(self.sq_C) <= 3)</syntaxhighlight>




<!--T:91-->
<center>[[File:sqvalidation3.jpg]]</center>
<center>[[File:sqvalidation3.jpg]]</center>




==Download==
==Download== <!--T:92-->




[[Media:ls2_test_em_sq_validation.lss|ls2_test_em_sq_validation.lss]]
<!--T:93-->
To download the survey sample used in the above examples, click on the following link: [[Media:ls2_test_em_sq_validation.lss|ls2_test_em_sq_validation.lss]].




=Sub-Question Relevance=
=Subquestion relevance= <!--T:94-->




==Overview==
==Overview== <!--T:95-->




This shows how array_filter and validation criteria can interact.  For validations that apply to sums, only relevant (visible) values are considered.
<!--T:96-->
This shows how array_filter and validation criteria can interact. For validations that apply to sums, only relevant (visible) values are considered.




==EM Features Demonstrated==
==EM Features Demonstrated== <!--T:97-->




#'''array_filter'''
<!--T:98-->
#'''array_filter_exclude'''
#[[QS:Array_filter|array_filter]]
#'''min_num_value'''
#[[QS:Array filter exclude|array_filter_exclude]]
#'''max_num_value'''
#[[QS:Min_num_value|min_num_value]]
#'''equals_num_value'''
#[[QS:Max num value|max_num_value]]
#[[QS:equals_num_value|equals_num_value]]


<!--T:99-->
It also shows dynamic reporting of the numbers of questions answered in the core questions.
It also shows dynamic reporting of the numbers of questions answered in the core questions.




==Screen Shots==
==Screenshots== <!--T:100-->




Changing the number of visible rows dynamically changes the sum.  Marking a sub-question as irrelevant doesn't clear its value. Rather, if it is irrelevant, its values don't contribute to any equation.
<!--T:101-->
Changing the number of visible rows dynamically changes the sum. Marking a subquestion as being irrelevant doesn't clear its value. Rather, if it is irrelevant, its values don't contribute to any equation.




<center>[[File:sqrel1.jpg]]</center>
<!--T:102-->
<center>[[File:sqrel1.jpg]][[File:Sqrelver12.png]]</center>




Note what happens when I check the "Fifth sub-question" for the first question ("Which rows should appear below").  Note that the sum for the second "Enter some numbers" question is now 5. Even though sub-question 5 for that question still have the value 14 (e.g. if you un-check the fifth sub-question, you will see the value of 14 again), that value does not contribute to the sum since it is currently irrelevant.  All irrelevant data is cleared (NULLed in the database) on submit, but stays available on the page in case users want or need to change their minds about answers.
<!--T:103-->
Note what happens when we check the "Fifth subquestion" for the first question '''"Which rows should appear below"'''. Note that the sum for the second "Enter some numbers" question is now 5. Even though subquestion 5 for that question still has the value 14 (e.g., if you un-check the fifth subquestion, you will see the value of 14 again), that value does not contribute to the sum since it is currently irrelevant. All irrelevant data is cleared (NULLed in the database) on submit, but it stays available on the page in case users want or need to change their minds about answers.




<!--T:104-->
<center>[[File:sqrel2.jpg]]</center>
<center>[[File:sqrel2.jpg]]</center>




==Download==
==Download== <!--T:105-->




[[Media:ls2_subquestion_relevance.lss|ls2_subquestion_relevance.lss]]
<!--T:106-->
To download our example, click here: [[Media:ls2_subquestion_relevance.lss|ls2_subquestion_relevance.lss]].




=Using Comma as Radix Separator (Decimal Point)=
=Using Comma as Radix Separator (Decimal Point)= <!--T:107-->




==Overview==
==Overview== <!--T:108-->




In addition, EM now ensures that only valid numbers can be entered into numeric fields.  In 1.91+, you could enter numbers like "1.2.3" or "-1.2-1", since it only checked that you were entering a number, decimal point, or negative sign.  In 1.92+, if you enter an invalid number, the field will be cleared and you have to re-enter the number.
<!--T:109-->
The ExpressionScript ensures that only valid numbers can be entered into numeric fields. If you enter an invalid number, you will be warned that something is wrong (e.g., in the case of the fruity theme, the whole question is "red-ed").


Note that the numeric values are always converted to using a period as the radix separator within the database.  That way statistical analyses will work appropriately.
<!--T:110-->
Note that the numeric values are always converted to using a period as the radix separator within the database. In this way, the statistical analyses will work appropriately.


==Question Types Using Radix Separator==
<!--T:111-->
To change the radix separator, access the [[Text elements]] options located under the [[Survey_settings|Settings]] tab, and look for the [[Text_elements#Survey_text_elements_panel|decimal mark]] functionality. 




#Numerical input <nowiki>[</nowiki>N]
<!--T:112-->
#Multiple numerical input <nowiki>[</nowiki>K]
{{Note|For more information on what a radix separator is, click [https://en.wikipedia.org/wiki/Radix_point|here].}}
#Array (Numbers) <nowiki>[</nowiki>:]
#Array (Texts) <nowiki>[</nowiki>;], when using the '''numbers_only''' advanced question option
#List (radio) <nowiki>[</nowiki>L], when using the '''other_numbers_only''' advanced question option
#Short free text <nowiki>[</nowiki>S], when using the '''numbers_only''' advanced question option
#Multiple short text <nowiki>[</nowiki>Q], when using the '''numbers_only''' advanced question option
#Multiple choice <nowiki>[</nowiki>M], when using the '''other_numbers_only''' advanced question option
#Multiple choice with comments <nowiki>[</nowiki>P], when using the '''other_numbers_only''' advanced question option




==Screenshots==
==Question Types Using Radix Separator== <!--T:113-->




Note that the following can use comma as the radix separator
<!--T:114-->
*validation messages (e.g. "Each answer must be between 1,5 and 8,2")
#[[Question type - Numerical input|Numerical input]] <nowiki>[</nowiki>N]
*totals (e.g. for the second question)
#[[Question type - Multiple numerical input|Multiple numerical input]] <nowiki>[</nowiki>K]
#[[Question type - Array (Numbers)|Array (Numbers)]] <nowiki>[</nowiki>:]
#[[Question type - Array (Texts)|Array (Texts)]] <nowiki>[</nowiki>;], when using the [[QS:Numbers_only|numbers_only]] attribute
#[[Question type - List (Radio)|List (radio)]] <nowiki>[</nowiki>L], when using the [[QS:Other_numbers_only|other_numbers_only]] attribute
#[[Question type - Short free text|Short free text]] <nowiki>[</nowiki>S], when using the [[QS:Numbers_only|numbers_only]] attribute
#[[Question type - Multiple short text|Multiple short text]] <nowiki>[</nowiki>Q], when using the [[QS:Numbers_only|numbers_only]] attribute
#[[Question type - Multiple choice|Multiple choice]] <nowiki>[</nowiki>M], when using the [[QS:Other_numbers_only|other_numbers_only]] attribute
#[[Question type - Multiple choice with comments|Multiple choice with comments]] <nowiki>[</nowiki>P], when using the [[QS:Other_numbers_only|other_numbers_only]] attribute




<center>[[File:radix1.jpg]]</center>
==Screenshots== <!--T:115-->




However, although you can now use commas for data entry into the Array (Texts) question, the row and column totals (and grand total) all display their values using a period as the radix separator.
<!--T:116-->
You may note in the below screenshots that comma can be used as a radix separator.




<center>[[File:radix2.jpg]]</center>
<!--T:117-->
<center>[[File:radix1.jpg]]</center>




==Download==
==Download== <!--T:118-->




[[Media:ls2_comma_as_radix_separator.lss|ls2_comma_as_radix_separator.lss]]
<!--T:119-->
To download the above example, click on the following link: [[Media:ls2_comma_as_radix_separator.lss|ls2_comma_as_radix_separator.lss]].




=Randomization Groups=
=Randomization Groups= <!--T:120-->




==Overview==
==Overview== <!--T:121-->




This survey demonstrates how to use the '''random_group''' advanced question option in 1.92+.
<!--T:122-->
This survey demonstrates how to make use of the '''random_group''' attribute.


Each time you start the survey, the question order is randomized.  However, once the survey is started, the randomization order remains fixed, even if you change languages.
<!--T:123-->
If this attribute is used, each time you start the survey, the question order is randomized. However, once the survey is started, the randomization order remains fixed, even if you change languages.




==Screenshots==
==Screenshots== <!--T:124-->




Here is the randomization paradigm.  The first random question on the page will either be Q1,Q4, or Q7. The second randomized question on the page will either be Q2, Q5, or Q8.
<!--T:125-->
Let's check together the below example. The first random question on the page will either be Q1 , Q4, or Q7. The second randomized question on the page will either be Q2, Q5, or Q8.




<!--T:126-->
<center>[[File:random1.jpg]]</center>
<center>[[File:random1.jpg]]</center>




<!--T:127-->
Here is the randomization generated the first time I tested this survey.
Here is the randomization generated the first time I tested this survey.




<!--T:128-->
<center>[[File:random2.jpg]]</center>
<center>[[File:random2.jpg]]</center>




<!--T:129-->
A different randomization was generated the second time I tested the survey.
A different randomization was generated the second time I tested the survey.




<!--T:130-->
<center>[[File:random3.jpg]]</center>
<center>[[File:random3.jpg]]</center>




<!--T:131-->
But, when I switched to French (without re-starting the survey), the randomization order remained intact.
But, when I switched to French (without re-starting the survey), the randomization order remained intact.




<!--T:132-->
<center>[[File:random4.jpg]]</center>
<center>[[File:random4.jpg]]</center>




==Download==
==Download== <!--T:133-->




[[Media:Randomization_Group_Test.lss|Randomization_Group_Test.lss]]
<!--T:134-->
To download the above example, click on the following link: [[Media:Randomization_Group_Test.lss|Randomization_Group_Test.lss]]




=Randomly Ask One Question Per Group=
=Randomly Ask One Question Per Group= <!--T:135-->




==Overview==
==Overview== <!--T:136-->




This survey shows how you can configure a survey to randomly display one question per group.  In it, there are 5 groups of 6 questions each.  At the outset, in Group 0, five hidden Equation questions, called ask1-ask5, are populated.  Each one has the value of {floor(rand(1,6.9999))} in the question text field, which means that the variables ask1-ask5 will each have a value between 1 and 6.  Then, each question in the group has a relevance equation like "ask1==N" where N is the Nth question in the group (so the third question in group 1 has the relevance equation  "ask1==3").
<!--T:137-->
This survey shows how you can configure a survey to randomly display one question per group. In it, there are 5 groups of 6 questions each. At the outset, in Group 0, five hidden Equation questions, called ask1-ask5, are populated. Each one has the value of {floor(rand(1,6.9999))} in the question text field, which means that the variables ask1-ask5 will each have a value between 1 and 6. Then, each question in the group has a relevance equation like "ask1==N" where N is the Nth question in the group (so the third question in group 1 has the relevance equation  "ask1==3").


This survey works equally well in survey-at-a-time, group-by-group, and question-by-question modes.  Since the randomization is set in the first group, and that group is effectively hidden (since all of the ask1-ask5 questions are hidden), the randomization stays the same for the subject; but each different subject will have a distinct randomization.
<!--T:138-->
This survey works equally well in survey-at-a-time, group-by-group, and question-by-question modes. Since the randomization is set in the first group, and that group is effectively hidden (since all of the ask1-ask5 questions are hidden), the randomization stays the same for the subject; but each different subject will have a distinct randomization.




==Features Demonstrated==
==Features Demonstrated== <!--T:139-->




#Equation question type
<!--T:140-->
#[[Question type - Equation|Equation question type]]
#Randomization functions
#Randomization functions
#Conditional (if) function
#Conditional (if) function




==Screenshots==
==Screenshots== <!--T:141-->




This is Group0, which uses the Equation question type to select random values from 1-6 for each group (except the last group, which only has 4 questions).  Note that the if() function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.
<!--T:142-->
This is Group0, which uses the [[Question type - Equation|Equation question type]] to select random values from 1 to 6 for each group (except the last group, which has only 4 questions).  Note that the "if()" function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.




<!--T:143-->
<center>[[File:randq3.jpg]]</center>
<center>[[File:randq3.jpg]]</center>




<!--T:144-->
This Group shows how the variable (ask4) from Group0 is used to control which question is visible within the fourth group.
This Group shows how the variable (ask4) from Group0 is used to control which question is visible within the fourth group.




<!--T:145-->
<center>[[File:randq2.jpg]]</center>
<center>[[File:randq2.jpg]]</center>




==Download==
==Download== <!--T:146-->




[[Media:limesurvey_survey_55164.lss|limesurvey_survey_55164.lss]]
<!--T:147-->
To download the above survey example, click here: [[Media:limesurvey_survey_55164.lss|Random questions within a group survey example]].




=Randomly Ask A Specific Number Of Questions In A Group (a sub-set of the questions)=
=Randomly Ask A Specific Number Of Questions In A Group (a subset of the questions)= <!--T:148-->




{{Alert|This is only for all random question in one group and for [[Creating a new survey#Presentation_.26_navigation|Group by group or All in one]] format}}
<!--T:149-->
{{Alert|This applies only to all random questions from one group and only if the [[General_settings#General_settings_panel|Group by group or All in one]] format is used.}}




==Overview==
==Overview== <!--T:150-->




This survey shows how to ask a random sub-set of questions in a group. For example, show a random 5 out of 10 questions in a group.  
<!--T:151-->
This survey shows how to ask a random subset of questions in a group. For example, show 5 random questions out of 10 questions located within a group.  


The survey has one group containing 10 questions. All questions are assigned the same [[Question type - Short free text#Randomization group_name (random group)|randomization group name]] so will be displayed in a random order on page load. Each question is given a relevance equation that the sum of the "[[Expression Manager#Access to Variables|relevanceStatus]]" of all other questions in the group is less than the number of questions you want to show. Since [[Expression Manager#Access to Variables|relevanceStatus]] is assigned as the questions are rendered, this effectively totals the number of preceding questions.
<!--T:152-->
The survey has one group containing 10 questions. All questions are assigned the same [[QS:Random_group|randomization group name]]. As a result, they will be displayed in a random order on page load. Each question is given a relevance equation that the sum of the "[[ExpressionScript#Access to Variables|relevanceStatus]]" of all other questions in the group is less than the number of questions you want to show. Since [[ExpressionScript#Access to Variables|relevanceStatus]] is assigned as questions are rendered, this effectively totals the number of preceding questions.


So, in our 5 out of 10 example, the equation for Q1 would be:<syntaxhighlight lang="php" enclose="div">sum(Q2.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5</syntaxhighlight>For Q2, it would be<syntaxhighlight lang="php" enclose="div">sum(Q1.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5</syntaxhighlight>And so on...
<!--T:153-->
So, in our 5 out of 10 example, the equation for Q1 would be:


<!--T:154-->
<syntaxhighlight lang="php">sum(Q2.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5</syntaxhighlight>


==Features Demonstrated==
<!--T:155-->
For Q2, it would be:


<!--T:156-->
<syntaxhighlight lang="php">sum(Q1.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5</syntaxhighlight>


#relevanceStatus variable
<!--T:157-->
#Randomizing
And so on...




==Download==
==Features Demonstrated== <!--T:158-->




[[Media:Random_5_out_of_10.lss|Random_5_out_of_10.lss]]
<!--T:159-->
#[[Expression_Manager#Access_to_Variables|relevanceStatus variable]]
#[[QS:Random group|Randomizing]]




=Rating User-Entered List of  Products=
==Download== <!--T:160-->




==Overview==
<!--T:161-->
To download the above example, click on the following link: [[Media:Random_5_out_of_10.lss|Random 5 out of 10 survey example]].


=Rating User-Entered List of Products= <!--T:162-->


This example shows how you can ask users to list a set of products that interest them, and then have them rate those products.


==Overview== <!--T:163-->


==EM Features Demonstrated==


<!--T:164-->
The below example shows how you can ask users to list a set of products that interest them, and then have them rate those products.


#'''Tailoring answers''' - when  rating products, the labels come from the comment field of the preceding multiple choice question
 
==EM Features Demonstrated== <!--T:165-->
 
 
<!--T:166-->
#'''Tailoring answers''' - when rating products, the labels come from the comment field of the preceding multiple choice question
#'''Tailoring scales''' - many advanced questions options, like scale headings, can also be tailored.
#'''Tailoring scales''' - many advanced questions options, like scale headings, can also be tailored.




==Screenshots==
==Screenshots== <!--T:167-->




This image shows that even though only products 1,3, and 5 were selected, only those 3 are displayed (using array_filter). Moreover, the row labels in the second question are either the Product number (if nothing is entered into the comment field), or the contents of the comment field.
<!--T:168-->
This image shows that even though only products 1,3, and 5 were selected, only those 3 are displayed (using the [[QS:Array_filter|array_filter]] attribute). Moreover, the row labels in the second question are either the product numbers (if nothing is entered into the comment field) or the contents of the comment fields.




<!--T:169-->
<center>[[File:mcc_filter1.jpg]]</center>
<center>[[File:mcc_filter1.jpg]]</center>




This image shows how the tailored answers are specified.
<!--T:170-->
This image shows how the tailored answers are specified:




<!--T:171-->
<center>[[File:mcc_filter2.jpg]]</center>
<center>[[File:mcc_filter2.jpg]]</center>




Here is the Show Logic File for that question, which lets us verify that the conditional logic will work as desired (e.g. there are no syntax errors)
<!--T:172-->
Here is the Show Logic File for that question, which lets us verify that the conditional logic works as desired (e.g., to see whether there are any syntax errors):




<!--T:173-->
<center>[[File:mcc_filter3.jpg]]</center>
<center>[[File:mcc_filter3.jpg]]</center>




This image shows a group in which you specify a 5 point rating scale (Options 1-5), the title of the scale, the products you want to rate.  The final question shows that each of the parts of the array question can be tailored.
<!--T:174-->
The next image shows a group in which you specify a 5 point rating scale (Options 1-5), the title of the scale, and the products you want to rate. The final question shows that each of the parts of the array question can be tailored:




<!--T:175-->
<center>[[File:mcc_filter4.jpg]]</center>
<center>[[File:mcc_filter4.jpg]]</center>




This image shows the logic file view of the last question.  As you can see, the sub-questions, answers, and scale headers can be tailored.
<!--T:176-->
The next image shows the logic file view of the last question. As you can observe, the subquestions, answers, and scale headers can be tailored.




<!--T:177-->
<center>[[File:mcc_filter5.jpg]]</center>
<center>[[File:mcc_filter5.jpg]]</center>




==Download==
==Download== <!--T:178-->
 


<!--T:179-->
To download the survey example from above, click on the following link: [[Media:Rating_User-Entered_List_of_Products_Survey.zip|Rating user-entered list of products survey example]].


[[Media:rating_user_entered_list_of_products.lss|rating_user_entered_list_of_products.lss]]
</translate>

Latest revision as of 14:58, 16 February 2022


Introduction

The best way to learn how to use the ExpressionScript is to play with working examples and modify them to your needs.

You may find below a set of sample surveys to demonstrate (and test) how the EM can be used to enhance your survey. These surveys can be found in the distribution's /docs/demosurveys folder.


Relevance, Tailoring and Equations

Overview

The following example computes the BMI (Body Mass Index) of each respondent. See below the features that are demonstrated within this example.

EM Features Demonstrated

  1. Relevance - support for powerful conditional logic;
  2. Piping / Tailoring - offers the ability to pipe or tailor answers and question metadata;
  3. Dynamic Tailoring - note that reports are changed on the page as you answer questions.
  4. Micro-Tailoring - conditional tailoring withing sentences and reports using if() statements
  5. Equations - a new question type that lets you do calculations and store the results in the database, even if the calculation is hidden
  6. Conditional Validation - validation criteria, such as the minimum allowable value, can be conditional - e.g., based upon equations.


Screenshots

This example computes the Body Mass Index, a calculation of your weight and height to determine whether you are overweight. Note that initially, all you see are the four mandatory questions:



Once you enter your information (and you get to choose whether to use metric or non-metric units), you see a tailored report that summarizes what you entered, telling you your weight status:



Here is a different example, using non-metric units to show how the result changes dynamically:



There are hidden Equation-type questions at the internal level that converts the data to metric (if needed), storing the metric height, weight, BMI, and weight status in the database without needing custom JavaScript.

You can see in the next set of examples how you can use mathematical and other functions within tailored reports. This is how the page looks like before you enter any data.  There is conditional logic to show blank cells if no (or non-numeric) data is entered, rather than showing "NaN" or "Divide by Zero".



As numbers are entered, the on-page report changes to show the computation being performed, and its result.



There are many other examples in this sample survey. For example, the below screenshot shows one of the dozens of ways you can fill out the Dynamic Relevance page. As the help text notes, try different ages, and especially illogical combinations of responses to see the amusing messages generated at the bottom. Also note that if you say that you have more than one child, the message will say "I hope you enjoy playing with your X children", rather than saying "I hope you enjoy playing with your child". This shows how you can easily micro-tailor sentences to make them match the gender and/or number of your subjects. You can even easily conjugate verbs and decline nouns based upon gender and number.



Download

To access the survey sample, please click on the following link: LS3_em_tailoring.zip.

Sample Census

Overview

This is a census example that asks how many people are in your household.

It demonstrates how group-level relevance can make it easier to implement a "loop" of questions. After creating the group for Person 1, I exported the group. Since I used qcode variable names like p1_name instead of the SGQA code, I could use a text editor to quickly edit and re-import the group several times (e.g., it took about 10 seconds to edit and re-import each repeating group, ensuring that all variables had unique variables names and that the group-level logic was correct).

You can also the copy question feature, but it won't be as fast as the option suggested above.

This also shows how you can prevent the Finished message from appearing until the survey is truly finished (e.g., when all needed groups are completed).


EM Features Demonstrated

  1. Group-level relevance - The follow-up groups (Person 1-5) only show for up to the number of cohabitants specified;
  2. Tailoring - The final report summarizes the demographic data for each cohabitant;
  3. Progressive question display - Whether in group or all-in-one mode, subsequent questions only show as soon as the preceding ones are answered.


Screenshots

The survey generates a tailored report showing the demographics of the specified number of cohabitants:



If you switch to question-at-a-time mode, you see that the index tailors the questions. Since the user said that the person is a woman, it asks "What is her name".  And since we answered "Mary", the next question says "How old is Mary"?



Download

To download the survey sample, click here: LS3_group_relevance.zip.


Cascading Array Filters

Overview

This survey is based on the design of a survey courtesy of Joy Lane Research, LLC.


Screenshots

In the following, note that:

  • Q02 only shows the set of products checked in Q01 (by using array_filter)
  • Q02 also shows "Another product", the text entered into the "Other electronic" field in Q01
  • Q04 only shows products from Q02 that were checked (so the array filter cascades)
  • Q05 only shows products from Q02 that were not checked in Q02 (using a cascaded array_filter_exclude)




Download

Click on the following link to download the above example: LS2_cascading_array_filter survey example.


Piping/Tailoring Using All Question Types and Attributes

Overview

If you are confused about how to name your variables (SGQA vs Qcodes), you are not alone. Although the main documentation describes how to compose Qcode variable names, nothing beats seeing it in a working demo.  This survey shows how you can access question attributes and responses using the ExpressionScript.


For this example, we recommend turning off the built-in HTML editor (or converting it to the pop-up mode) when editing this survey. It can take a minute or more for the HTML editor to render the large HTML reports in edit mode.


Content

  • Examples of every question type
  • All questions types that can use "other" are included so that you can see how that affects variable naming
  • Default values for all the question types that accepts defaults
  • Tailoring - On- and off-page reports showing all 16 available EM dot notation suffixes.
  • These reports show all of the currently entered data (so show you how you could generate your own printable reports for users in lieu of the print-answers screen)
  • Proper Qcode and SGQA naming of all variables


Screenshots

This is a huge survey, so we chose not to include screen shots. Instead, please download and play with it.


Download

Click on the following link to download the survey: LS3_EM_question_attributes.lss


Traditional validation, re-envisioned

Overview

This demonstrates all the validation types that make use of expressions and how they affect each of the question types that support validation. In many cases, the validation tips start hidden and only appear if a question fails validation criteria (thus also disappearing once the question passes the validation criteria).


Validation Types Demonstrated

  1. min_num_value_n - minimum value for an answer
  2. max_num_value_n - max value for an answer
  3. min_answers - minimum number of answers required
  4. max_answers maximum number of answers allowed
  5. multiflexible_min - minimum value allowed for an answer (for multiflexi numbers question type)
  6. multiflexible_max - maximum value allowed for an answer (for multiflexi numbers question type)
  7. min_num_value - minimum allowed sum across all answers for the question
  8. max_num_value - maximum allowed sum across all answers for the question
  9. equals_num_value - the sum across all answers for the question must equal this value
  10. validation - this is the regular expression validation for the question - it can apply to individual cells


Screenshots

Using new CSS styles, each validation type shows up a separate tip. If they are shown, they can be hidden via the hide_tip option. The default option is to show them with red font if the question fails the validation criteria, and green if it passes them:



A user cannot submit a page with validation errors. They will be immediately warned if they entered wrong information:



Validation can be applied to individual cells within an array, such as in this example where regular expression validations ensure that each entry is a properly formatted US phone number including area code.



Download

To download the above example, click on the following link: LS3_Validation_tests.zip.


Validation Equations

Overview

Sometimes you need custom validation that cannot be achieved using the traditional min/max criteria. For this, you will need to use the em_validation_q and em_validation_sq options which let you construct complex validation equations at the question and subquestion level, respectively.


At the subquestion level, we also introduce the "this" variable to make it easy to validate each cell in an array without needing to know its variable name. For more details about it, click here.


EM Features Demonstrated

  1. em_validation_q - this is an equation that determines whether the whole question is valid
  2. em_validation_q_tip - this is the message to show if the question fails em_validation_q criteria
  3. em_validation_sq - this is the equation that determines whether each subquestion (array cell) is valid
  4. em_validation_sq_tip - this is the message to show if any of the subquestions is invalid.

In general, when em_validation_sq is used, if any cell is invalid, the background color for that cell turns red to indicate that there is an error.


Screenshots


This question ensures that you enter the ages of your children in descending order by applying this validation equation:

q1_sq1 >= q1_sq2 && q1_sq2 >= q1_sq3 && q1_sq3 >= q1_sq4





In the below example, the validation ensures that no more than 3 questions are answered on any given row by applying this validation equation:

(sum(Test_A_1, Test_A_2, Test_A_3, Test_A_4, Test_A_5) <= 3) && (sum(Test_B_1, Test_B_2, Test_B_3, Test_B_4, Test_B_5) <= 3) && (sum(Test_C_1, Test_C_2, Test_C_3, Test_C_4, Test_C_5) <= 3)

You can also write this as follows, LimeSurvey automatically converting it at run-time to the above-listed expression.

(sum(self.sq_A) <= 3) && (sum(self.sq_B) <= 3) && (sum(self.sq_C) <= 3)



Download

To download the survey sample used in the above examples, click on the following link: ls2_test_em_sq_validation.lss.


Subquestion relevance

Overview

This shows how array_filter and validation criteria can interact. For validations that apply to sums, only relevant (visible) values are considered.


EM Features Demonstrated

  1. array_filter
  2. array_filter_exclude
  3. min_num_value
  4. max_num_value
  5. equals_num_value

It also shows dynamic reporting of the numbers of questions answered in the core questions.


Screenshots

Changing the number of visible rows dynamically changes the sum. Marking a subquestion as being irrelevant doesn't clear its value. Rather, if it is irrelevant, its values don't contribute to any equation.



Note what happens when we check the "Fifth subquestion" for the first question "Which rows should appear below". Note that the sum for the second "Enter some numbers" question is now 5. Even though subquestion 5 for that question still has the value 14 (e.g., if you un-check the fifth subquestion, you will see the value of 14 again), that value does not contribute to the sum since it is currently irrelevant. All irrelevant data is cleared (NULLed in the database) on submit, but it stays available on the page in case users want or need to change their minds about answers.



Download

To download our example, click here: ls2_subquestion_relevance.lss.


Using Comma as Radix Separator (Decimal Point)

Overview

The ExpressionScript ensures that only valid numbers can be entered into numeric fields. If you enter an invalid number, you will be warned that something is wrong (e.g., in the case of the fruity theme, the whole question is "red-ed").

Note that the numeric values are always converted to using a period as the radix separator within the database. In this way, the statistical analyses will work appropriately.

To change the radix separator, access the Text elements options located under the Settings tab, and look for the decimal mark functionality.


For more information on what a radix separator is, click [https://en.wikipedia.org/wiki/Radix_point


Question Types Using Radix Separator

  1. Numerical input [N]
  2. Multiple numerical input [K]
  3. Array (Numbers) [:]
  4. Array (Texts) [;], when using the numbers_only attribute
  5. List (radio) [L], when using the other_numbers_only attribute
  6. Short free text [S], when using the numbers_only attribute
  7. Multiple short text [Q], when using the numbers_only attribute
  8. Multiple choice [M], when using the other_numbers_only attribute
  9. Multiple choice with comments [P], when using the other_numbers_only attribute


Screenshots

You may note in the below screenshots that comma can be used as a radix separator.



Download

To download the above example, click on the following link: ls2_comma_as_radix_separator.lss.


Randomization Groups

Overview

This survey demonstrates how to make use of the random_group attribute.

If this attribute is used, each time you start the survey, the question order is randomized. However, once the survey is started, the randomization order remains fixed, even if you change languages.


Screenshots

Let's check together the below example. The first random question on the page will either be Q1 , Q4, or Q7. The second randomized question on the page will either be Q2, Q5, or Q8.



Here is the randomization generated the first time I tested this survey.



A different randomization was generated the second time I tested the survey.



But, when I switched to French (without re-starting the survey), the randomization order remained intact.



Download

To download the above example, click on the following link: Randomization_Group_Test.lss


Randomly Ask One Question Per Group

Overview

This survey shows how you can configure a survey to randomly display one question per group. In it, there are 5 groups of 6 questions each. At the outset, in Group 0, five hidden Equation questions, called ask1-ask5, are populated. Each one has the value of {floor(rand(1,6.9999))} in the question text field, which means that the variables ask1-ask5 will each have a value between 1 and 6. Then, each question in the group has a relevance equation like "ask1==N" where N is the Nth question in the group (so the third question in group 1 has the relevance equation  "ask1==3").

This survey works equally well in survey-at-a-time, group-by-group, and question-by-question modes. Since the randomization is set in the first group, and that group is effectively hidden (since all of the ask1-ask5 questions are hidden), the randomization stays the same for the subject; but each different subject will have a distinct randomization.


Features Demonstrated

  1. Equation question type
  2. Randomization functions
  3. Conditional (if) function


Screenshots

This is Group0, which uses the Equation question type to select random values from 1 to 6 for each group (except the last group, which has only 4 questions).  Note that the "if()" function first checks whether ask1 has already been set, and if so, uses that value. If the value hasn't been set, then it uses a random value to set the value of ask1.



This Group shows how the variable (ask4) from Group0 is used to control which question is visible within the fourth group.



Download

To download the above survey example, click here: Random questions within a group survey example.


Randomly Ask A Specific Number Of Questions In A Group (a subset of the questions)

  This applies only to all random questions from one group and only if the Group by group or All in one format is used.



Overview

This survey shows how to ask a random subset of questions in a group. For example, show 5 random questions out of 10 questions located within a group.

The survey has one group containing 10 questions. All questions are assigned the same randomization group name. As a result, they will be displayed in a random order on page load. Each question is given a relevance equation that the sum of the "relevanceStatus" of all other questions in the group is less than the number of questions you want to show. Since relevanceStatus is assigned as questions are rendered, this effectively totals the number of preceding questions.

So, in our 5 out of 10 example, the equation for Q1 would be:

sum(Q2.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5

For Q2, it would be:

sum(Q1.relevanceStatus, Q3.relevanceStatus, Q4.relevanceStatus, Q5.relevanceStatus, Q6.relevanceStatus, Q7.relevanceStatus, Q8.relevanceStatus, Q9.relevanceStatus, Q10.relevanceStatus) LT 5

And so on...


Features Demonstrated

  1. relevanceStatus variable
  2. Randomizing


Download

To download the above example, click on the following link: Random 5 out of 10 survey example.

Rating User-Entered List of Products

Overview

The below example shows how you can ask users to list a set of products that interest them, and then have them rate those products.


EM Features Demonstrated

  1. Tailoring answers - when rating products, the labels come from the comment field of the preceding multiple choice question
  2. Tailoring scales - many advanced questions options, like scale headings, can also be tailored.


Screenshots

This image shows that even though only products 1,3, and 5 were selected, only those 3 are displayed (using the array_filter attribute). Moreover, the row labels in the second question are either the product numbers (if nothing is entered into the comment field) or the contents of the comment fields.



This image shows how the tailored answers are specified:



Here is the Show Logic File for that question, which lets us verify that the conditional logic works as desired (e.g., to see whether there are any syntax errors):



The next image shows a group in which you specify a 5 point rating scale (Options 1-5), the title of the scale, and the products you want to rate. The final question shows that each of the parts of the array question can be tailored:



The next image shows the logic file view of the last question. As you can observe, the subquestions, answers, and scale headers can be tailored.



Download

To download the survey example from above, click on the following link: Rating user-entered list of products survey example.