HowTo Filter the Columns of an Array (Numbers)

More
7 years 6 months ago #109458 by scottturnbull
Is there a way in the LimeSurvey dialogs to control the visibility of columns in an array (numbers) question?

I am working on implementing a survey in which a set of actions is presented in a multi choice list.
i.e.
"Select the following types of communication you participate in with one or more of your contacts."

A subsequent question will present a lengthy list of contacts, and ask that the participant mark which communication actions are engaged in with each contact.

This is being created as questions of type Array (numbers) with the checkbox option enabled. The desired result is a grid of checkboxes with communication types as columns and contacts as the rows.

We would like the list of actions from the setup question to be used as an array filter for the columns of the array numbers question type. Only those actions that the participant stated they sometimes use would be shown as a checkbox option for each listed contact.

I can easily manage using an array filter from a previous question to control display of array (numbers) rows, but I haven't found a way to have an array filter control array (numbers) columns.

To restate my opening question,
Is there a way in the LimeSurvey dialogs, or is a bit of custom javascript the only way to hide columns based on previous answer values?
The topic has been locked.
More
7 years 6 months ago #109462 by tpartner
You will need to use JavaScript for that.

For inspiration - manual.limesurvey.org/Workarounds:_Manip...2Multiple-Options.22.


.

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: scottturnbull
The topic has been locked.
More
7 years 6 months ago #109464 by Bigred01
I read in a previous forum post that someone created a multiple choice question for each column then by using float left on them, they lined them up side by side. (I wish i could find a link to point you to it..If i do i will add it to this post)

The answer options were also in a multiple choice question with the same amount of options but the checkboxes were hidden. The text lined up with all of the other questions.

Instead of using the array filter, you can set the relevance for each "column"(question) separately.

This approach would allow you to use all of the built in limesurvey exclusive options available for multiple choice questions but will involve some styling on your part to get it looking right.

If you do it like this though you will probably want a fixed question width so the columns wont stack when the window is resized or the respondent has a low resolution.
The following user(s) said Thank You: scottturnbull
The topic has been locked.
More
7 years 5 months ago #109893 by scottturnbull
I was hoping I had simply missed the combination of dialog knobs that would give control of column visibility.

As with many such projects, the requirements shift, and the need to hide the columns has faded away. It was a worthy exercise in use of techniques for the javascript merging of multiple questions into a single composite question on the screen. I'll tuck the technique into my toolbox for use another day.

Thanks, all.
The topic has been locked.
More
5 years 7 months ago #135099 by first
Bigred wrote:

I read in a previous forum post that someone created a multiple choice question for each column then by using float left on them, they lined them up side by side. (I wish i could find a link to point you to it..If i do i will add it to this post)


I tried it some time but demo survey was hosted on limeservice which is not expired. Anyway i will try to rewrite the code and share.

You can find this thread quickly remembering it as first thread in plugins folder :)

www.limesurvey.org/forum/plugins/95000-c...nd-exclusive-options

Survey Designer and Programmer
The topic has been locked.
More
5 years 7 months ago #135102 by first
Its almost done. You may need to adjust some look and feel or maybe tpartner will help us to extend this script so that it works without any modification.

#We create as many multi questions as we need columns.
#The move those column side by side with float left.
#Adjust labels.

Benefits:
#You can hide columns with relevance.
#Sub-question relevance will still work.
#You can make use advance setting that are multi choice question.

File Attachment:

File Name: limesurvey...3985.lss
File Size:37 KB


Tested with Version 2.06+ Build 150612 default template.

Survey Designer and Programmer
Attachments:
The topic has been locked.
More
5 years 7 months ago #135109 by DenisChenu
Hi,

Plugin : git.framasoft.org/SondagePro-LimeSurvey-plugin/hideEmptyColumn
Demo : demonstration.sondages.pro/655577

Not tested in 2.50 surely some css to update

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.
The following user(s) said Thank You: socius
The topic has been locked.
More
5 years 2 months ago #141890 by ericwu
Hello

Tried to modify the function filterArrByCol for filter Array (Numbers) by Columns, but it is not working.
I am not good at Javascript, can someone point me out?

function filterArrNumberByCol(qMultiOpt, qArray, prevPage) {
 
    // If filter question is on a previous page, hide Q1 and check all "visible" boxes
	if(prevPage == 1) {
		$('#question'+qMultiOpt+' li[id^="javatbd"]:visible input.checkbox').attr('checked', true);
		$('#question'+qMultiOpt+'').hide();
	}
 
	// Assign classes to the answer cells
	$('#question'+qArray+' td.answer-item').each(function(i){
		var classArr = $(this).attr('class').split('answer_cell_00');
		classArr = classArr[1].split(' ');
		var ansCode = classArr[0];
		$(this).addClass('ans-'+ansCode+' filtered');
	});
 
	// Assign classes to the answer label cells
	$('#question'+qArray+' table.subquestions-list tbody tr:eq(0) td.answer-item').each(function(i){
		var classArr2 = $(this).attr('class').split(' ans-');
		var ansCode2 = classArr2[1];
		$('#question'+qArray+' table.subquestions-list thead tr:eq(0) th:eq('+i+')').addClass('ans-'+ansCode2+'');
	});
 
	// Fire the filter function on page load
	filterArr(qMultiOpt, qArray);
 
	// Listener on multi-opt checkboxes to fire the filter function
	$('#question'+qMultiOpt+' input.checkbox').click(function(){
		filterArr(qMultiOpt, qArray);
	});
 
	// On submit, clear all hidden checkboxs of array
	$('#movenextbtn, #movesubmitbtn').click(function(){
		$('#question'+qArray+' td.filtered:hidden').each(function(i){
				$('input.checkbox', this).prop('checked', false);
		});
		return true;
	});
}
 
function filterArr(qMultiOpt, qArray) {
 
	if($('#question'+qMultiOpt+' input.checkbox:checked').length < 1) {
		// Hide the array if no multi-opt options are checked
		$('#question'+qArray+'').hide();
	}
	else {
		$('#question'+qArray+'').show();
 
		// Hide all columns of array
		$('#question'+qArray+' table.subquestions-list tbody td.answer-item, #question'+qArray+' table.question thead th').hide();
 
		// Loop through multi-opt checkboxes and, if checked, show corresponding column of array
		$('#question'+qMultiOpt+' input.checkbox').each(function(i){
			if($(this).prop('checked') === true) {
				var classArr3 = $(this).attr('id').split('X'+qMultiOpt);
				var ansCode3 = classArr3[1];
				$('#question'+qArray+' .ans-'+ansCode3+'').show();
			}
		});
	}
}
The topic has been locked.
More
5 years 2 months ago - 5 years 2 months ago #141891 by DenisChenu
Did you look at my post and try the plugin : limesurvey.sondages.pro/974296

Stil some cosmetic issue, but still working .

For remind : framagit.org/SondagePro-LimeSurvey-plugin/hideEmptyColumn

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.
Last edit: 5 years 2 months ago by DenisChenu. Reason: Update link
The following user(s) said Thank You: ericwu
The topic has been locked.
More
5 years 2 months ago #141893 by ericwu
Thank you Denis.
This is very helpful.
The topic has been locked.
More
4 years 11 months ago #146776 by Haap
Hi all,

I was looking into this, because the built-in filters for Array (Numbers) questions don't seem to work.

It might be just me, but I am running into a problem using this plugin as well. When using the plugin (and also when lookint at Denis' sample site) I am unable to correctly hide the empty columns. I am running the latest LimeSurvey (2.58.0+ 20170104).

Please see the attached screenshot.



This is especially annoying when using Mandatory questions ;-). So any help on how to filter the Array (numbers) question type is appreciated.

Cheers, Haap
Attachments:
The topic has been locked.
More
4 years 10 months ago #146862 by DenisChenu

....and also when lookint at Denis' sample site....

It's not my sample website, it's my dev website. Updated to git each night.

Plugin was deactivated, work again.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.
The topic has been locked.
More
4 years 3 months ago - 4 years 3 months ago #157760 by socius
Hi!

thanks @DenisChenu for the helpful hideEmptyColumns plugin that seems exactly what I need to avoid too large arrays that scare respondents away! :-)

Unfortunately it seems that I have a similar problem as @Haap some months ago - the filtering does not work as intended (s. screenshots).

I use Limesurvey 2.6.4-lts from the github repository github.com/LimeSurvey/LimeSurvey/tree/2.06lts (cloned on 170617), my template is the SkeletonQuest extensions.sondages.pro/skeletonquest-rwd-for-limesurvey/, and I just cloned the plugin from github.com/SondagesPro/LS-hideEmptyColumn.git, unzipped and uploaded to plugins/hideEmptyColumn - and checked with the demosurvey. My result s. screenshots. Did I miss something here?

Thank you very much for the plugin and your help!
Attachments:
Last edit: 4 years 3 months ago by socius. Reason: forgot to mention the upload to plugins/hideEmptyColumn
The topic has been locked.
More
4 years 3 months ago #157848 by DenisChenu
I can't answer like this … in general it work then withoiut see the survey in live : can not answer

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development . I don't answer to private message.
The topic has been locked.
More
4 years 3 months ago #157868 by socius
Hi @DenisChenu,

thanks for your response! I'll install and try it again. The demo on limesurvey.sondages.pro/655577.html?lang=en seems broken (?) May I ask you to set this up again? Maybe I can find the error by comparison of the html sources of the working example on your server and the not yet working example on mine.

Thank you very much!
Best, G
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now