Multi-Array dual scale

More
3 months 3 days ago #179431 by Olegna001
Hi, I’m new to Lime Survey, but doing lots of reading at the moment. I have a challenge to solve.

Can anyone tell me if it is possible to create an Array Dual Scale with multiple fields (not just 2)?

If this is possible, please share your solution?

To explain it further; I’m trying to create a question group. Each question is different, but the sub-questions for each is the same. And to answer the sub-questions I would like to provide the user with drop downs with preset answer options.

Example:

Question Group = Tennis

Q1 = Playing Tennis
Sub Q1a = Do you play? (Drop down = Yes; No)
Sub Q1b = How often?
(Drop down = Daily, Weekly, Monthly)
Sub Q1c = How much time per session (Drop down = 30 min; 45 min; 1 hr; 1:5 hr; 2 hrs; 2.5 hrs or more)

Question Group = Squash
Q2 = Playing Squash
same sub questions as above

Question Group = Golf
Etc...etc...

Appreciate your help.

Also, is it possible to create this solution without custom code? If not, that’s ok, just trying to look for the easiest way to solve this challenge.

Thanks,
AG

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
3 months 2 days ago #179442 by tpartner
Replied by tpartner on topic Multi-Array dual scale
You may be able to adapt this workaround to your needs.

- www.limesurvey.org/forum/can-i-do-this-w...list?start=15#173576

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

Please Log in or Create an account to join the conversation.

More
3 months 1 day ago #179448 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Hi Tony,

Thanks. I've imported your solution to review and test out. It's great; the general idea is right, however, how do I switch it around? (i.e. I need consistent drop-downs populating down the columns, not across as rows)? Appreciate your help. Apologies, coding isn't my best skill.


Thanks,
AG

Please Log in or Create an account to join the conversation.

More
3 months 1 day ago #179468 by tpartner
Replied by tpartner on topic Multi-Array dual scale
This example will insert consistent drop-downs in columns:

<script type="text/javascript" charset="utf-8">
 
	$(document).on('ready pjax:scriptcomplete',function(){
		var thisQuestion = $('#question{QID}');
 
		// Column specific classes
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('th, td', this).each(function(i) {
				$(this).addClass('column-'+i);
			});
		});
 
		// Insert selects into column 1
		if($('.answer-item.column-1 .inserted-select', thisQuestion).length == 0) {
			$('.answer-item.column-1', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
				<option value="">Please choose...</option>\
				<option value="1">Yes</option>\
				<option value="2">No</option>\
				<option value="3">Do not know</option>\
			</select>');
		} 
 
		// Insert selects into column 2
		if($('.answer-item.column-2 .inserted-select', thisQuestion).length == 0) {
			$('.answer-item.column-2', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
				<option value="">Please choose...</option>\
				<option value="1">Red</option>\
				<option value="2">Blue</option>\
				<option value="3">Pink</option>\
				<option value="3">Purple</option>\
			</select>');  
		} 
 
		// Listeners on select elements
		$('.inserted-select', thisQuestion).on('change', function(i) {
			if($(this).val() != '') {
				$(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).trigger('change');
			}
			else {
				$(this).closest('.answer-item').find('input:text').val('').trigger('change');
			}
		});
 
		// Returning to page
		$('.with-select input:text', thisQuestion).each(function(i) {
			var thisCell = $(this).closest('.answer-item');
			var inputText = $.trim($(this).val());
			var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
			$('select.inserted-select', thisCell).val(selectval);
		});
 
		// Clean-up styles
		$('select.inserted-select', thisQuestion).css({
			'max-width': '100%'
		});
		$('.with-select input:text', thisQuestion).css({
			'position': 'absolute',
			'left': '-9999em'
		});
	});
</script>



Sample survey attached:

File Attachment:

File Name: limesurvey...1223.lss
File Size:28 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: Olegna001

Please Log in or Create an account to join the conversation.

More
2 months 4 weeks ago #179570 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Hi Tony, this is just what I needed. Works perfectly and I have been able to adapt the code for my needs. Thanks very much!

Please Log in or Create an account to join the conversation.

More
2 months 4 weeks ago #179571 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Another few questions Tony:
1. How do I make column 1 mandatory to force the user to select either Yes or No?
2. And also, if they select Yes, the remaining columns in that row should be mandatory also, but if they select No, they do not need to complete the remaining columns.
3. Lastly, for the very first column, that does not have a heading, how do I add tooltips for each row?

I believe all of the above can be done through the UI editor, but now as I am dealing with custom code, I assume I need to modify the code to enable this functionality?

Really appreciate your help.

Thanks,
Angelo

Please Log in or Create an account to join the conversation.

More
2 months 3 weeks ago #179684 by tpartner
Replied by tpartner on topic Multi-Array dual scale
1. & 2. This can be done with a question validation equation like this:

(that.Q1.sq_Y001_X001 == 'Yes' OR (that.Q1.sq_Y001_X001 == 'No' AND count(that.Q1.sq_Y001) == 4))
AND
(that.Q1.sq_Y002_X001 == 'Yes' OR (that.Q1.sq_Y002_X001 == 'No' AND count(that.Q1.sq_Y002) == 4))
AND
(that.Q1.sq_Y003_X001 == 'Yes' OR (that.Q1.sq_Y003_X001 == 'No' AND count(that.Q1.sq_Y003) == 4))
AND
(that.Q1.sq_Y004_X001 == 'Yes' OR (that.Q1.sq_Y004_X001 == 'No' AND count(that.Q1.sq_Y004) == 4))


3. In LimeSurvey 3.x, you can use Bootstrap Tooltips . So, something like this in the sub-question text:

<a href="#" data-toggle="tooltip" title="" data-original-title="Tooltip content 1">this has a tooltip</a>



Sample survey attached:

File Attachment:

File Name: limesurvey...2231.lss
File Size:36 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: Olegna001

Please Log in or Create an account to join the conversation.

More
2 months 3 weeks ago #179792 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Hi Tony,

This is fantastic, thanks very much for your help. Through your support, I’m really enjoying the use of this tool & learning a lot.

One more question if you don’t mind:

4. Is it possible to hide or make the first column (I.e. column 0 in your example above without a heading) width smaller, or so that it adapts to the width of the text contents? For some tables it makes sense to have the first column visible, but for others I don’t need it. Appreciate if you could tell me both methods (I.e. hide completely, or make the width fits cell contents)

Thanks again for your support!

Cheers,
Angelo

Please Log in or Create an account to join the conversation.

More
2 months 3 weeks ago #179812 by tpartner
Replied by tpartner on topic Multi-Array dual scale
There is a question setting for the sub-question width - manual.limesurvey.org/Question_type_-_Ar...subquestion_width.29

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: Olegna001

Please Log in or Create an account to join the conversation.

More
2 months 3 weeks ago #179833 by Olegna001
Replied by Olegna001 on topic Multi-Array dual scale
Brilliant! Found the setting. Works like a gem - thanks again Tony!

Cheers,
Angelo

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!