Array numbers with checkbox and an exclusive option

More
7 years 1 week ago #121722 by eloner
Hello,
I have a question like that:



(type: array numbers with checkbox).

and the following subquestions:



I need to set LimeSurvey in order to uncheck all the flags on a row if "I don't know" is chosen.
How can I set this condition?
I tried to insert SQ004 (the code for "I don't know") in the field "Exclusive option" (Advanced settings), but it doesn't work...
Am I missing something?
Here is the question code:

File Attachment:

File Name: limesurvey...3347.lsq
File Size:6 KB


Thanks to everybody for the help!
Elo






P.S. I use LS Version 2.05+ Build 150520
Attachments:
The topic has been locked.
More
7 years 1 week ago #121732 by holch
Have a look here: I think this describe exactly your problem:
www.limesurvey.org/en/community-services...e-of-these-exclusion

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: eloner
The topic has been locked.
More
7 years 1 week ago #121740 by eloner
Thank you Holch,
I used the workaround manual.limesurvey.org/Workarounds:_Manip..._Excludes_All_Others to my question, but apparently it doesn't work.
What I require is:
- to uncheck all the first options of a row if I choose the last
- to uncheck the last option of a row if a choose one of the first
I enclose a copy of the question with the javascript added according to Tony Partner's workaround:

File Attachment:

File Name: limesurvey...47-2.lsq
File Size:9 KB

(I use the default standard template).
Cheers,
Elo
Attachments:
The topic has been locked.
More
7 years 1 week ago - 7 years 1 week ago #121763 by tpartner
Hmm...it seems that there was a typo in that workaround which I have fixed.

Here it is with the typo fixed and support for relevance:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		// Call the exclude function using question ID
		excludeOpt({QID});
	});
 
	// A function to make the last option in each array row exclusive
	function excludeOpt (qID) {
 
		var thisQuestion = $('#question'+qID)
 
		// Add some classes to the checkbox cells
		$('td.checkbox-item', thisQuestion).addClass('normalOpt');
		$('tr.subquestions-list', thisQuestion).each(function(i) {
			$('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt')
		});
 
		// A listener on the checkbox cells
		$('td.checkbox-item', thisQuestion).click(function (event) {
			handleExclusive($(this));
		});
 
		// A listener on the checkboxes
		$('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) {
			handleExclusive($(this).closest('td'));
		});
 
		function handleExclusive(thisCell) {
 
			var thisRow = $(thisCell).closest('tr');
 
			// Uncheck the appropriate boxes in a row
			if ($(thisCell).hasClass('normalOpt')) {
				$('.exlusiveOpt input[type="checkbox"]', thisRow).attr('checked', false);
			}
			else {
				$('.normalOpt input[type="checkbox"]', thisRow).attr('checked', false);
			}
 
			// Check conditions (relevance)
			$('td.checkbox-item', thisRow).each(function(i) {
				var thisValue = '';
				if($('input[type="checkbox"]', this).is(':checked')) {
					thisValue = 1;
				}
				var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
				$('input[type="hidden"]', thisRow).attr('value', 'thisValue');
				fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
			});
		}
	}
</script>

Here's a sample survey with some added questions to display relevance functionality:

File Attachment:

File Name: limesurvey...1451.lss
File Size:22 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 7 years 1 week ago by tpartner.
The following user(s) said Thank You: eloner
The topic has been locked.
More
7 years 1 week ago - 7 years 1 week ago #121764 by eloner
Now it works perfectly!
Thank you Tony!
And... you can evaluate the quality of a program also from the quality of the answers you get to your doubts and questions! ;)
Cheers,
Elo

P.S. I have written an e-mail about a donation to LimeSurvey. As soon as we get a response we can send our contribution to the project
Last edit: 7 years 1 week ago by eloner. Reason: typos in editing
The following user(s) said Thank You: tpartner
The topic has been locked.
More
7 years 6 days ago #121845 by david2013
What if I want exclusive option for each column instead of each row. Do we have a workaround too?
The topic has been locked.
More
7 years 6 days ago #121847 by tpartner
David, use this to make the last row exclusive:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		// Call the exclude function using question ID
		excludeOpt({QID});
	});
 
	// A function to make the last option in each array row exclusive
	function colExcludeOpt (qID) {
 
		var thisQuestion = $('#question'+qID)
 
		// Add some classes to the checkbox cells
		$('td.checkbox-item', thisQuestion).addClass('normalOpt');
		$('tr.subquestions-list:last td.checkbox-item', thisQuestion).removeClass('normalOpt').addClass('exlusiveOpt')
 
		// And some column-specific attributes
		$('tr.subquestions-list', thisQuestion).each(function(i){
			$('td.answer-item', this).each(function(i){
				$(this).attr('data-column', i+1);
			});
		});
 
		// A listener on the checkbox cells
		$('td.checkbox-item', thisQuestion).click(function (event) {
			handleColExclusive($(this));
		});
 
		// A listener on the checkboxes
		$('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) {
			handleColExclusive($(this).closest('td'));
		});
 
		function handleColExclusive(thisCell) {
 
			var thisColumn = $(thisCell).attr('data-column');
 
			// Uncheck the appropriate boxes in a row
			if ($(thisCell).hasClass('normalOpt')) {
				$('.exlusiveOpt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).attr('checked', false);
			}
			else {
				$('.normalOpt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).attr('checked', false);
			}
 
			// Check conditions (relevance)
			$('td.checkbox-item[data-column="'+thisColumn+'"]', thisQuestion).each(function(i) {
				var thisValue = '';
				if($('input[type="checkbox"]', this).is(':checked')) {
					thisValue = 1;
				}
				var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
				$('input[type="hidden"]', this).attr('value', 'thisValue');
				fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
			});
		}
	}
</script>

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: david2013
The topic has been locked.
More
7 years 6 days ago #121848 by tpartner
eloner, I found a small bug that may affect conditional questions. Please use this revised code:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		// Call the exclude function using question ID
		excludeOpt({QID});
	});
 
	// A function to make the last option in each array row exclusive
	function excludeOpt (qID) {
 
		var thisQuestion = $('#question'+qID)
 
		// Add some classes to the checkbox cells
		$('td.checkbox-item', thisQuestion).addClass('normalOpt');
		$('tr.subquestions-list', thisQuestion).each(function(i) {
			$('.normalOpt:last', this).removeClass('normalOpt').addClass('exlusiveOpt')
		});
 
		// A listener on the checkbox cells
		$('td.checkbox-item', thisQuestion).click(function (event) {
			handleExclusive($(this));
		});
 
		// A listener on the checkboxes
		$('td.checkbox-item input[type="checkbox"]', thisQuestion).click(function (event) {
			handleExclusive($(this).closest('td'));
		});
 
		function handleExclusive(thisCell) {
 
			var thisRow = $(thisCell).closest('tr');
 
			// Uncheck the appropriate boxes in a row
			if ($(thisCell).hasClass('normalOpt')) {
				$('.exlusiveOpt input[type="checkbox"]', thisRow).attr('checked', false);
			}
			else {
				$('.normalOpt input[type="checkbox"]', thisRow).attr('checked', false);
			}
 
			// Check conditions (relevance)
			$('td.checkbox-item', thisRow).each(function(i) {
				var thisValue = '';
				if($('input[type="checkbox"]', this).is(':checked')) {
					thisValue = 1;
				}
				var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
 
				$('input[type="hidden"]', this).attr('value', 'thisValue');
				fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
			});
		}
	}
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
4 years 1 month ago #168850 by stephanied
I would like to implement this code on version 2.73.1
The goal is to uncheck "no involvement" if any of the other options in a column are selected and uncheck the all other options in a column once "no involvement" is selected.

If we could take it another further step by disabling selections per column after "no involvement" is selected, that would be great, but it's not needed.

I have attached a photo of my current question layout -- Array(numbers)
Attachments:
The topic has been locked.
More
4 years 1 month ago #168859 by tpartner
Can you attach a small sample survey?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
4 years 1 month ago #168862 by stephanied
Unfortunately I cannot publicly post a sample survey, however, I can personal message you a link.
The topic has been locked.
More
4 years 1 month ago #168864 by tpartner
A link to a survey does not help with development and I don't have time to create test surveys for everyone.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
4 years 1 month ago - 4 years 1 month ago #168866 by stephanied
My apologies. Are you more so looking for the survey structure (.lss)?
Attachments:
Last edit: 4 years 1 month ago by stephanied.
The topic has been locked.
More
4 years 1 month ago #168915 by tpartner
This script will render the last row of an array-checkboxes as exclusive. Additionally, when a check-box in the last row is checked, all other check-boxes in that column are disabled.

<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		var thisQuestion = $('#question{QID}')
 
		// Add column-specific classes
		$('tr.subquestion-list', thisQuestion).each(function(i) {
			$('th, td', this).each(function(i) {
				$(this).addClass('column-'+i).attr('data-column', i);
			});
		});
 
		// Add some classes to the checkbox cells
		$('td.checkbox-item', thisQuestion).addClass('normal-opt');
		$('tr.subquestion-list:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt');
 
		// A listener on the checkboxes
		$('td.checkbox-item input[type="checkbox"]', thisQuestion).change(function (event) {
			handleExclusive($(this).closest('td'));
		});
 
		function handleExclusive(thisCell) {
 
			var thisColumn = $(thisCell).attr('data-column');
			var thisCheckBox = $('input[type="checkbox"]', thisCell);
 
			// Uncheck the appropriate boxes in a row
			$('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('disabled', false);
			if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) {
				$('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden').val('');
				$('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false);
			}
			else if ($(thisCheckBox).is(':checked')) {
				$('.normal-opt[data-column="'+thisColumn+'"] input:hidden').val('');
				$('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false).prop('disabled', true);
			}
 
			// Check conditions (relevance)
			$('td.checkbox-item[data-column="'+thisColumn+'"]').each(function(i) {
 
				var thisValue = '';
				var itemCheckBox = $('input[type="checkbox"]', this);
				var thisSGQA = $(itemCheckBox).attr('id').replace(/cbox_/, '');
				var aelt = $('#answer'+thisSGQA);
 
				fixnum_checkconditions($(aelt).val(), thisSGQA, 'hidden');
				checkconditions($(itemCheckBox).attr('value'), $(itemCheckBox).attr('name'), $(itemCheckBox).attr('type'))
			});
		}
	});
</script>



Here is your test survey back with that script in the source of the array:

File Attachment:

File Name: limesurvey...2581.lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.

Start now!

Just create your account and start using Limesurvey today.

Register now