Array filter exclusion

More
3 years 11 months ago - 3 years 11 months ago #101142 by id_wahyu
id_wahyu created the topic: Array filter exclusion
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: 3 years 11 months ago by id_wahyu. Reason: edit wording

Please Log in to join the conversation.

More
3 years 11 months ago #101153 by tpartner
tpartner replied the topic: Array filter exclusion
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.

Please Log in to join the conversation.

More
3 years 11 months ago #101161 by id_wahyu
id_wahyu replied the topic: Array filter exclusion
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.

Please Log in to join the conversation.

More
3 years 11 months ago #101165 by tpartner
tpartner replied the topic: Array filter exclusion
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.

Please Log in to join the conversation.

More
3 years 11 months ago #101168 by id_wahyu
id_wahyu replied the topic: Array filter exclusion
Please find attached.

File Attachment:

File Name: h7cc8467.lsg
File Size:39 KB
Attachments:

Please Log in to join the conversation.

More
3 years 11 months ago #101171 by tpartner
tpartner replied the topic: Array filter exclusion
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.

Please Log in to join the conversation.

More
3 years 11 months ago #101172 by id_wahyu
id_wahyu replied the topic: Array filter exclusion
Thanks for the prompt reply Tony.
Do you have any sample or documentation on how to create that hidden question?

Please Log in to join the conversation.

More
3 years 11 months ago - 3 years 6 months ago #101177 by tpartner
tpartner replied the topic: Array filter exclusion
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.
Attachments:
Last Edit: 3 years 6 months ago by tpartner.

Please Log in to join the conversation.

More
3 years 11 months ago #101198 by id_wahyu
id_wahyu replied the topic: Array filter exclusion
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?

Please Log in to join the conversation.

More
3 years 11 months ago #101210 by tpartner
tpartner replied the topic: Array filter exclusion
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.
The following user(s) said Thank You: id_wahyu

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now