Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: hide empty rows of a matrix

hide empty rows of a matrix 2 years 9 months ago #69372

  • Xtale
  • Xtale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 17
  • Karma: 0
Hello!

My survey involves a matrix with checkboxes as follows:

var1 [] [] []
var2 [] [] []
var3 [] [] []
...

where the item "varX" is a previously answered item of an expandable 25-row textfield array. The array is not required to be filled out completely. Unfortunately, all cells including the empty ones are taken over to the checkbox array so I need to find a way to hide the empty rows.

I already messed around with some code snippets from a board user but I cant get it to work. I would appreciate some help.

Regards
x
$(document).ready(function() {
 
		handleRows(50);
 
		function handleRows(q1ID) {
 
			// Loop through all Q1 rows
			$('#question'+q1ID+' tbody[id^="javatbd"]').each(function(i) {
 
				// Hide empty rows in Q1
				if($('input[type="text"]:last', this).val() == '') { 
					$(this).hide(); 
				}
 
 
			});
		}
	});
The administrator has disabled public write access.

Re: hide empty rows of a matrix 2 years 9 months ago #69392

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4138
  • Thank you received: 767
  • Karma: 348
Can you provide a sample survey?
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: 2 years 9 months ago by tpartner.
The administrator has disabled public write access.

Re: hide empty rows of a matrix 2 years 9 months ago #69433

  • Xtale
  • Xtale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 17
  • Karma: 0
Thank you! Is this sufficent?
explain.jpg
The administrator has disabled public write access.

Re: hide empty rows of a matrix 2 years 9 months ago #69439

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4138
  • Thank you received: 767
  • Karma: 348
Can you attach an export of the survey or group so we can test?
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.

Re: hide empty rows of a matrix 2 years 9 months ago #69448

  • Xtale
  • Xtale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 17
  • Karma: 0
oh sry, here is the file

File Attachment:

File Name: limesurvey_survey_66537.lss
File Size: 55 KB
The administrator has disabled public write access.

Re: hide empty rows of a matrix 2 years 9 months ago #69453

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4138
  • Thank you received: 767
  • Karma: 348
No problem.

Add this script to the second group. It will hide all array rows that do not have a label or have the default sub-question text.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		// Hide all rows without a row label
		$('table.question tbody').each(function(i, el){
 
			var rowLabel = $('th:first', el).text().replace(/[\s\n\t]/g,'');
 
			if(rowLabel == '' || rowLabel == 'Newansweroption') {
				$(el).hide();
			}
		});
 
		// Fix up row background colours
		$('table.question tbody:visible tr').each(function(i, el){
			$(el).removeClass('array1, array2');
			if(i % 2 == 0) {
				$(el).addClass('array2');
			}
			else {
				$(el).addClass('array1');
			}
		});
 
	});
</script>
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: Xtale

Re: hide empty rows of a matrix 2 years 9 months ago #69479

  • Xtale
  • Xtale's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 17
  • Karma: 0
thank you! works perfect :) I'll donate to support your great work
The administrator has disabled public write access.

Re: hide empty rows of a matrix 2 years 9 months ago #69497

  • Mazi
  • Mazi's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 5324
  • Thank you received: 294
  • Karma: 249
Xtale wrote:
thank you! works perfect :) I'll <a href='donate.limesurvey.org'>donate</a> to support your great work
Thanks for your support!

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: hide empty rows of a matrix 2 years 8 months ago #70897

Hi tpartner,

I am a newbie and definitely not a coder. I am very impressed with LimeSurvey and your level of support here.

Your answer for Xtale is very nice, but I'm still don't get how to modify for my situation. My problem is similar to Xtale's except that in my survey design the original question is a one-row by five-column (1x5) text array:

SubQ: [__A1___] [__A2___] [__A3___] [__A4___] [__A5___]


My users are also not asked to complete all fields, so there may be less than all five.

-->I would like to take the answers users do provide for this question and put them alongside another text array (5x5) as SubQ prompts (same as Xtale's design except text-boxes, not check-boxes):


A1: [_____] [_____] [_____] [_____] [_____]

A2: [_____] [_____] [_____] [_____] [_____]

A3: [_____] [_____] [_____] [_____] [_____]

A4: [_____] [_____] [_____] [_____] [_____]

A5: [_____] [_____] [_____] [_____] [_____]


And also like Xtale, I would like to have rows presented only for those (Ax's) that were answered in the initial question.

I appreciate any guidance you can provide!
The administrator has disabled public write access.

Re: hide empty rows of a matrix 2 years 8 months ago #70930

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4138
  • Thank you received: 767
  • Karma: 348
This solution should work for you as-is if you:

1) Place your questions on separate pages

2) Use {INSERTANS} to load the labels for the Q2 subquestions

3) Set up your survey to use JavaScript and place the script in the source of Q2
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: 2 years 8 months ago by tpartner.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.191 seconds
Donation Image