Welcome, Guest
Username: Password: Remember me

TOPIC: Looping through a set of Questions (Sub-surveys?)

Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73497

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
I'm pretty sure this can't be done in 1.92, but might be supported in LS2. I have a set of questions that I need to loop though, with different field types. For example, let's say the questions are about your children. I want a button that says "Add Child" which pops up a mini-survey -- what's the child's name? Gender? Birthdate? In-school? History of medical issues?

All of those are different field types, it would be nice to have validation.

One solution is to use a text array. This is a hack for several reasons -- you have to artificially limit the number of children, and the format of an array means that very field is just text, and is the same size, so in_school (which should be a checkbox) takes up the same amount of space as medical_history.

Another solution is to have a separate survey of children, and make sure the token is set to allow multiple uses of it, as described in docs.limesurvey.org/Iterate+Survey but this seems a bit suspect as well.

Other ideas (besides waiting for version 2)?

Tac
The administrator has disabled public write access.

Re: Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73502

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
You can do this in 1.92. LS2 uses the same EM engine that 1.92 uses, so no need to wait for it.

Here's how I've done it in the past:
(1) Create a group that allows you to ask any and all questions you might want to ask about the child. Embed conditions or relevance equations to only ask the questions you need. Also embed any required validation logic.
(2) Export that group, and re-import it as many times as you need. Although you don't want to set an artificial limit, it is probably safe to assume that a parent won't have more than 20 children, for example - so import the group 20 times.
(3) On a page before this set of repeating groups, ask the user how many children they have - let's call that variable "numKids"
(4) For each group, change the group description to make it more readable - e.g. "Child #1", "Child #2", ...
(5) Change the group-level relevance for each group. So, for Child #1, the group-level relevance would be numKids >= 1 and for Child #8, it would be numKids >= 8

Note, you should really change the variable names within each of the groups - adding a prefix or suffix to indicate which child you are referring to - otherwise when you export to SPSS or R your variable labels will be confused. However, for backwards compatibility with 1.91, if you use the conditions designer instead of relevance, you can re-use the same question names within group and still be sure that the appropriate conditions will be applied. If you Show Logic File, you'll see a number of "pink" warnings, but the survey itself should work.
The administrator has disabled public write access.

Re: Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73509

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5301
  • Thank you received: 291
  • Karma: 247
TMSWhite wrote:
(5) Change the group-level relevance for each group. So, for Child #1, the group-level relevance would be numKids >= 1 and for Child #8, it would be numKids >= 8
You can also do that by using conditions. Set a condition on the first question of the group like "Show question X if question Y was answered ">=3"". then copy that condition to all following questions of that group. Set conditions for following groups as well, using "...answered >=4" and so on.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Re: Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73531

  • tacman1123
  • tacman1123's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 125
  • Karma: 1
Brainstorming: suppose I separated out the children question (it's not really a children question, but it's easier to describe that way) into a separate survey.

I could use the iterate survey feature, and allow a single token to access the survey multiple times. Then my only question is how to list the surveys on a page so you know whether or not to edit a survey or add a new one.

In other words, on the main list surveys page, I want to list my main survey, list the survey RESULTS of the "children" survey, with the option of adding a new "child".

So I'd see the following surveys:
Family Survey
List Children:
Michael 10/12/71 Male [edit]
Kathleen 9/1/75 Female [edit]
[Add Another Child]

Is there a way to do that in the current scripting language? Or would it need to be completely external?

Tac
The administrator has disabled public write access.

Re: Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73566

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5301
  • Thank you received: 291
  • Karma: 247
All this has to be coded. I have done similar work for 2-3 customers of mine and coding your own overview page as you described above using PHP is possible and probably the best way to do so.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
Last Edit: 2 years 5 months ago by Mazi.
The administrator has disabled public write access.

Re: Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73606

  • dbrd
  • dbrd's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 11
  • Thank you received: 2
  • Karma: 1
tacman1123 wrote:
Brainstorming: suppose I separated out the children question (it's not really a children question, but it's easier to describe that way) into a separate survey.....

Tac

I approach it as TMSWhite suggested:

"(2) Export that group, and re-import it as many times as you need. Although you don't want to set an artificial limit, it is probably safe to assume that a parent won't have more than 20 children, for example - so import the group 20 times."

The export and re-import is easy, and if minor editing of text is needed, of a question code for example, a quick search and replace in a text editor will work.

This is how I construct my surveys, which require going through a group of questions multiple times.
The administrator has disabled public write access.

Re: Looping through a set of Questions (Sub-surveys?) 2 years 5 months ago #73615

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5301
  • Thank you received: 291
  • Karma: 247
That is also the approach we recommend for looping.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.146 seconds
Donation Image