Actions

Expression Manager sample surveys

From LimeSurvey Manual

Revision as of 15:16, 30 March 2012 by TMSWhite (talk | contribs)

Introduction

The Limesurvey distribution includes sample surveys in the /docs/demosurveys folder that demonstrate all of the main Expression Manager-related functionality.  This page provides an overview of the functionality they provide, plus a convenient means of downloading them.

Sample Census

Overview

This is a pretend census that asks how many people are in your household, asks tailored follow-up for each person (up to 5), and generates a simple report.

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).

This also shows how you can prevent the Finished message from appearing until the survey is truly finished (e.g. 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 co-habitants specified.
  2. Tailoring - The final report summarizes the demographic data for each co-habitant
  3. Progressive question display - Whether in group or all-in-one mode, subsequent questions only show as soon as the preceding ones are answered.

Screen Shots

The survey generates a tailored report showing demographics of the specified number of co-habitants:

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

ls2_group_relevance.lss

Cascading Array Filters

Overview

This survey is based off 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 were 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).

Screen Shots

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)

Here, note the new behavior of array_filter_exclude (compared to version 1.91+):

  • If the exclusive option is selected, it hides all of the other choices, rather than disabling them
  • 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.

Download

ls2_cascading_array_filter.lss

All Question Types and Attributes

Overview

This survey shows how you can access question attributes and responses using Expression Manager. It provides:

  • Samples of every question type
  • Default values for any question type that accepts defaults
  • On and Off-Page Reports showing all 16 available EM dot notation suffixes
  • Proper Qcode and SGQA naming of all variables

Download

ls2_EM_question_attributes.lss

Traditional Validation, Re-envisioned

Overview

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+.

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

Screen Shots

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.

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.

This color coding also applies to validation sums.

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

ls2_validation_tests.lss

Validation Equations

Overview

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

  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 sub-question (array cell) is valid
  4. 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.

Screen Shots

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

This question 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)

Download

ls2_test_em_sq_validation.lss

Sub-Question 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 show dynamic reporting of the numbers of questions answered in the core questions.

Screen Shots

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, it's values don't contribute to any equation.

Download

ls2_subquestion_relevance.lss