Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: How Array_filter in previous Array (Text) question and Array question result

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #111978

  • oikos
  • oikos's Avatar
  • Offline
  • Junior Lime
  • Posts: 24
  • Karma: 0
Hi!

Q1 is an Array question with Yes/No answer options; Q2 is an Array (Text) question. And I want the Q2 question have only the selected subquestions marked as 'Yes' in the previous Q1 question.

So, I've put an Array_filter in Q2 question with Q1 code question, but the problem is that all subquestions appear in Q2, as such whether the answer is Yes as No.

In Q2 I just want the subquestions marked as Yes in Q1... Please, how do I do it?
Attachments:
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #112054

  • oikos
  • oikos's Avatar
  • Offline
  • Junior Lime
  • Posts: 24
  • Karma: 0
Please, can someone help?
Tony Partner, please, could you give me some suggestion?
Thank's in advance.
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #112066

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6199
  • Thank you received: 1374
  • Karma: 538
Well, if both questions are on the same page you can use JavaScript to simply filter the rows of Q2 but you will run into trouble if Q2 is mandatory. (a hidden unanswered row in Q2 will prevent moving ahead in the survey)

I think you will need to:
1) add a hidden multiple-choice question
2) use JavaScript to dynamically check the multiple-choice boxes according to the Q1 answers
3) filter Q2 on the hidden question

Can you attach a small sample survey containing that group?


.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
The following user(s) said Thank You: oikos

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #112071

  • oikos
  • oikos's Avatar
  • Offline
  • Junior Lime
  • Posts: 24
  • Karma: 0
Tony, thank you very much!

Here the example: Demo.limesurvey.org/index.php?r=survey/index/sid/726616/lang/es

At the backend ( How Array_filter (ID 726616) ): Demo.limesurvey.org/index.php?r=admin/su...view/surveyid/726616

Please, could you show how the JavaScript code would be? I'm newbie about it.

A) If both questions are on the same page?
B) If each question is on different pages?

I hope not to abuse your generosity, but really you help me a lot. Thanks!
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #112077

  • oikos
  • oikos's Avatar
  • Offline
  • Junior Lime
  • Posts: 24
  • Karma: 0
Sorry, the links are broken.
New link in frontend: www.instituto-csic.es/uclm.grokis/limesu...x.php/346763?lang=es

Question group in attachment (notice: default language is Spanish)
Attachments:
Last Edit: 1 year 11 months ago by oikos. Reason: orthography
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #112088

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6199
  • Thank you received: 1374
  • Karma: 538
1) Set up your survey to use JavaScript.

2) Directly after Q1, add a multiple-choice question with the same sub-questions and codes as Q1 (we'll call this "qHidden").

3) Set Q2 (and any subsequent arrays) to be array-filtered by qHidden.

4) Add the following script to the source of the qHidden. This will:
- hide qHidden
- put a listener on the Q1 radios
- if a radio in column 1 of Q1 is clicked, the corresponding checkbox in qHidden is checked and the array filter handles the display of rows in Q2

<script type="text/javascript" charset="utf-8">	
    $(document).ready(function(){
 
		// Identify the questions
		var qHiddenID = ('{QID}');
		var qHidden = $('#question'+qHiddenID);
		var q1 = $(qHidden).prevAll('.array-flexible-row:eq(0)');
		var q1ID = $(q1).attr('id').split('question')[1];
 
		// Hide the hidden question
		$(qHidden).css({
			'position': 'absolute',
			'left': '-999em'
		});
 
		// Add some column-specific classes to Q1
		$('table.subquestions-list tr', q1).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('column-'+i);
			});
		});
 
		// Listener on Q1
		$('input.radio', q1).change(function(event){
 
			// Reset the hidden question
			$('input.checkbox', qHidden).prop('checked', false);
			$('li.question-item input[type="hidden"]', qHidden).val('');
 
			// Check the appropriate boxes in the hidden question
			$('.column-1 input.radio:checked', q1).each(function(i) {
				var thisCode = $(this).attr('id').split('X'+q1ID)[1].split('-')[0];
				$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).prop('checked', true);
				$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).next('input[type="hidden"]').val('Y');
			});	
 
			// Fire the array filter
			$('input.checkbox', qHidden).each(function(i) {
				checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
			});	
		});
	});
</script>

Here's a working survey (with an additional array in a following group also filtered by qHidden). In this survey, I also added the following relevance to Q2 and Q3 so the whole question is hidden unless a radio in column 1 of Q1 is clicked:
CI1_SQ001 == 'A1' || CI1_SQ002 == 'A1' || CI1_SQ003 == 'A1'

File Attachment:

File Name: limesurvey...3531.lss
File Size:26 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 1 year 11 months ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: oikos

How Array_filter in previous Array (Text) question and Array question result 1 year 11 months ago #112103

  • oikos
  • oikos's Avatar
  • Offline
  • Junior Lime
  • Posts: 24
  • Karma: 0
Wow, that looks great! That's exactly what I was looking for, it works perfectly! Thank you very much for all your work on this, Tony!
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 2 weeks ago #130827

  • aehruesch
  • aehruesch's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Hello,
I tried to adapt the Code above and it works fine if I'm just interested in the first column. Is there a way to enhance it to the second column (all in all I have 4 columns)?
My JS-skills are very limited (all I know I basically learned in this forum). It would be nice to know, what I have to change in the code above to make my example work.
Thanks in advance,
Eric
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 2 weeks ago #130913

  • aehruesch
  • aehruesch's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
I solved it myself with a little trial and error.

Anyway, this is the changed code for column 1 and 2:
Hidden question to filter following array(s). <script type="text/javascript" charset="utf-8">	
    $(document).ready(function(){
 
		// Identify the questions
		var qHiddenID = ('{QID}');
		var qHidden = $('#question'+qHiddenID);
		var q1 = $(qHidden).prevAll('.array-flexible-row:eq(0)');
		var q1ID = $(q1).attr('id').split('question')[1];
 
		// Hide the hidden question
		$(qHidden).css({
			'position': 'absolute',
			'left': '-999em'
		});
 
		// Add some column-specific classes to Q1
		$('table.subquestions-list tr', q1).each(function(i){
			$('> *', this).each(function(i){
				$(this).addClass('column-'+i);
			});
		});
 
		// Listener on Q1
		$('input.radio', q1).change(function(event){
 
			// Reset the hidden question
			$('input.checkbox', qHidden).prop('checked', false);
			$('li.question-item input[type="hidden"]', qHidden).val('');
 
			// Check the appropriate boxes in the hidden question
			$('.column-1 input.radio:checked', q1).each(function(i) {
				var thisCode = $(this).attr('id').split('X'+q1ID)[1].split('-')[0];
				$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).prop('checked', true);
				$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).next('input[type="hidden"]').val('Y');
			});	
			$('.column-2 input.radio:checked', q1).each(function(i) {
				var thisCode = $(this).attr('id').split('X'+q1ID)[1].split('-')[0];
				$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).prop('checked', true);
				$('input.checkbox[id$="X'+qHiddenID+thisCode+'"]', qHidden).next('input[type="hidden"]').val('Y');
			});
 
			// Fire the array filter
			$('input.checkbox', qHidden).each(function(i) {
				checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
			});	
		});
	});
</script>
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 2 weeks ago #130926

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9295
  • Thank you received: 1330
  • Karma: 386
Actaully, witha 2.06 version : really more easy to use "Relevance equation" for sub quetsion.

This topic is set when this setting don't exist.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.
The following user(s) said Thank You: tpartner

How Array_filter in previous Array (Text) question and Array question result 6 months 1 week ago #131188

  • bogika0107
  • bogika0107's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
Can you show me the more easy way with example, because i try the script and any other codes etc. and didn't work. I use 2.06 version. I have to exactly the same solution than Oikos. :\
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 1 week ago #131192

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5094
  • Thank you received: 755
  • Karma: 227
Well, the easy way is to use relevance equations on subquestions, as Dennis said above.

Just as for questions or questions group, from 2.06 onwards you can show/hide subquestions via the relevance equations for each subquestion.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 1 week ago #131194

  • bogika0107
  • bogika0107's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
Thank you for your answer, but I still don't undertand yet.
So: I have a question Yes (igen) and No(nem) and more than one answer (U can see it in the picture). and I want the Q2 question have only the selected subquestions marked as 'Yes' in the previous Q1 question. If I would have just One answer i used to the Array filter, but it's not working now. And the relevance equation not editable because i have another condition. What should i have to do?
Attachments:
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 1 week ago #131196

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5094
  • Thank you received: 755
  • Karma: 227
Well, if I understood you right, then your problem is actually totally different to what was originally asked. You want a question pre-marked depending on the previous question, if I understood you right?

The OP wanted to show only those subquestions in Q2 that received a certain answer in Q1.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
The administrator has disabled public write access.

How Array_filter in previous Array (Text) question and Array question result 6 months 1 week ago #131197

  • bogika0107
  • bogika0107's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 9
  • Karma: 0
That's what I want: it was the original problem in this topic (the one different that my Q2's type not text, radius) : "Q1 is an Array question with Yes/No answer options; Q2 is an Array (Text) question. And I want the Q2 question have only the selected subquestions marked as 'Yes' in the previous Q1 question.

So, I've put an Array_filter in Q2 question with Q1 code question, but the problem is that all subquestions appear in Q2, as such whether the answer is Yes as No."

I added a file (image) with az example: I just want to see Q2 what in Q1 was marked yes(igen). i don't want to see in Q2 what was No (nem) in Q1! Does it possible? Arrey filter doesn't work!
Attachments:
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.373 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form