Welcome, Guest
Username: Password: Remember me

TOPIC: Array filter exclusion

Array filter exclusion 5 months 3 weeks ago #101142

  • id_wahyu
  • id_wahyu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Hi All.
I need some advice and how to deal with "Array filter" or "Array filter exclusion".
It said that for Multiple choice question(s) (separated by semicolons).

My case:
Q1a_FM - Brand Awa FM
Q1a_OTH - Brand Awa Others
Q1b_FM - Ad Awa FM

So at Q1b_FM, at the "Array-filter" option I defined Q1a_FM;Q1a_OTH. But it's not working properly, only show the answer of Q1a_FM.

Any advice for me please.
Last Edit: 5 months 3 weeks ago by id_wahyu. Reason: edit wording
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101153

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
When filtering by multiple questions, if an answer code exists in BOTH filter questions, it must be selected in BOTH filter questions before it will appear in the filtered question.

If an answer code only exists in ONE of the filter questions, it only needs to be selected in that question before it will appear in the filtered question.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101161

  • id_wahyu
  • id_wahyu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Thanks Tony, for my case Q1a_FM and Q1a_OTH are exclusive each other.

How write the "Array filter" for multiple questions?
I tried "Q1a_FM; Q1a_OTH" but only show Q1a_FM input.

Thanks.
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101165

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Can you attach an exported sample survey with that group?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101168

  • id_wahyu
  • id_wahyu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Please find attached.

File Attachment:

File Name: h7cc8467.lsg
File Size: 39 KB
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101171

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Ah, now I see your problem. There is no way to satisfy the "must be selected in BOTH filter questions" requirement.

I think the only solution would be to insert a hidden question and use JavaScript to toggle its check-boxes as Q1a_FM and Q1a_OTH are answered. You could then filter Q1b_FM with the hidden question.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101172

  • id_wahyu
  • id_wahyu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Thanks for the prompt reply Tony.
Do you have any sample or documentation on how to create that hidden question?
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101177

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
1) Set up your survey to use JavaScript.

2) Copy Q1a_FM and place the new question after Q1a_OTH. Lets call the new question "Q1a_Hidden".

3) Filter Q1b_FM by Q1a_Hidden.

4) Add the following script to the source of Q1a_Hidden.

The script hides Q1a_Hidden and puts a listener on the check-boxes in Q1a_FM and Q1a_OTH. If either are found to be checked, the corresponding option in Q1a_Hidden is checked and the checkconditions() function is fired.

<script type="text/javascript" charset="utf-8">	
	$(document).ready(function(){
 
		// Identify some stuff
		var qHiddenID = {QID};
		var hiddenQuestion = $('#question'+qHiddenID);
		var prevQuestions = $(hiddenQuestion).prevAll('.multiple-opt');
		var q1ID = $(hiddenQuestion).prevAll('.multiple-opt:eq(1)').attr('id').replace(/question/, '');
		var q2ID = $(hiddenQuestion).prevAll('.multiple-opt:eq(0)').attr('id').replace(/question/, '');
 
		// Hide the hidden question
		$(hiddenQuestion).hide();
 
		// Listener on the first two multiple-choice questions
		$('input.checkbox', prevQuestions).change(function(event){
 
			// Identify some more stuff
			var thisQuestionCode = $(this).closest('.multiple-opt').attr('id').replace(/question/, '');
			var thisAnswerCode = $(this).attr('id').split('X'+thisQuestionCode)[1];
			var hiddenOption = $('input.checkbox[id$="X'+qHiddenID+thisAnswerCode+'"]');
 
			// Find if either of the filter options are checked
			var filterChecked = false;
			if($('input.checkbox[id$="X'+q1ID+thisAnswerCode+'"]').is(':checked') || $('input.checkbox[id$="X'+q2ID+thisAnswerCode+'"]').is(':checked')) {
				filterChecked = true;
			}
 
			// Toggle the hidden option accordingly
			if(filterChecked != $(hiddenOption).is(':checked')) {
				$(hiddenOption).trigger('click');
				checkconditions($(hiddenOption).attr('value'), $(hiddenOption).attr('name'), $(hiddenOption).attr('type'));
			}
		});
	});
</script>


Here is a working example:

File Attachment:

File Name: h2aadb73.lss
File Size: 62 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 weeks 5 days ago by tpartner.
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101198

  • id_wahyu
  • id_wahyu's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 26
  • Karma: 0
Thanks for the help Tony.
But, it is working perfect if I use option "Group by Group", and is not with "Question by question" - the Q1a_hidden keep showing.

Any step that I missed Tony?
The administrator has disabled public write access.

Array filter exclusion 5 months 3 weeks ago #101210

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
This solution will only work if all questions are on the same page.JavaScript can only manipulate elements that exist in the current page.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: id_wahyu
Moderators: ITEd
Time to create page: 0.139 seconds
Donation Image